PostgreSQL
A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

Replace anything within <placeholder> accordingly

Console

Console

$ psql #logs in to default database & default user
$ sudo -u <rolename:postgres> psql #logs in with a particular user

Commands

Commands

  • Show roles: \du
  • Show tables: \dt
  • Show databases: \l
  • Connect to a database: \c <database>
  • Show columns of a table: \d <table> or \d+ <table>
  • Quit: \q

Creating database

Creating database

 $ createdb databasename