Skip to content

Common Comands

List All Databases

bash
postgres=# \l
NameOwnerEncodingLocale ProviderCollateCtypeLocaleICU RulesAccess privileges
FooBarBazpostgresUTF8libcEnglish_United States.1252English_United States.1252
EmployeepostgresUTF8libcEnglish_United States.1252English_United States.1252
postgis_36_samplepostgresUTF8libcEnglish_United States.1252English_United States.1252
postgrespostgresUTF8libcEnglish_United States.1252English_United States.1252
template0postgresUTF8libcEnglish_United States.1252English_United States.1252=c/postgres; postgres=CTc/postgres
template1postgresUTF8libcEnglish_United States.1252English_United States.1252=c/postgres; postgres=CTc/postgres

List All Tables

bash
postgres=# \dt
SchemaNameTypeOwner
publicexpensestablepostgres
publicexpenses_by_categorytablepostgres
publicmanifesttablepostgres
publicraw_manifesttablepostgres

Connect to Database

bash
postgres=# \c

List All Schemas

bash
postgres=# \dn
NameOwner
pgagentpostgres
publicpg_database_owner

List All roles

bash
postgres=# \du
Role nameAttributes
postgresSuperuser, 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=# \! cls

I 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.