Skip to content

Instantly share code, notes, and snippets.

@PlanetRoast
Last active August 29, 2015 14:22
Show Gist options
  • Save PlanetRoast/4fbabbbc0efd6f54b650 to your computer and use it in GitHub Desktop.
Save PlanetRoast/4fbabbbc0efd6f54b650 to your computer and use it in GitHub Desktop.
#blog

PSQL Cheat Sheet

Working with PostgreSQL via the Ubuntu terminal is great but sometimes I need a reminder for some of the commands. Here is a list of the things I do most often in PSQL.

Console

  • Open Postgres console: PSQL
  • Quit: \q

Databases

  • List all: \l
  • Connect to a database: \c database_name
  • Delete database: drop database database_name;

Tables

  • List all tables: \dt
  • Delete all rows in table: delete from tablename
  • Drop table: drop table table_name;

Select

  • Kitchen sink select * from table_name;
  • Specific columns select firstName, lastName from users;

Users

  • List roles \du
  • Add password to role ALTER USER davide WITH PASSWORD 'hu8jmn3';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment