Common Comands
List All Databases
bash
postgres=# \l| Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges |
|---|---|---|---|---|---|---|---|---|
| FooBarBaz | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | |||
| Employee | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | |||
| postgis_36_sample | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | |||
| postgres | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | |||
| template0 | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | =c/postgres; postgres=CTc/postgres | ||
| template1 | postgres | UTF8 | libc | English_United States.1252 | English_United States.1252 | =c/postgres; postgres=CTc/postgres |
List All Tables
bash
postgres=# \dt| Schema | Name | Type | Owner |
|---|---|---|---|
| public | expenses | table | postgres |
| public | expenses_by_category | table | postgres |
| public | manifest | table | postgres |
| public | raw_manifest | table | postgres |
Connect to Database
bash
postgres=# \cList All Schemas
bash
postgres=# \dn| Name | Owner |
|---|---|
| pgagent | postgres |
| public | pg_database_owner |
List All roles
bash
postgres=# \du| Role name | Attributes |
|---|---|
| postgres | Superuser, Create role, Create DB, Replication, Bypass RLS |
Window Users
If you are on windows and need to clear the screen while in psql environment use the following command.
bash
postgres=# \! clsI could just list them all out, but the help page is easily available. Dig in. You do not need to memorize these! When you have a problem, the help page is a reference.