PostgreSQL psql Commands Cheat Sheet — CLI Navigation & Queries
Essential psql terminal meta-commands (\l, \c, \dt, \d+), query execution plan inspection, backups (pg_dump), and database maintenance.
Terminal Meta-Commands
\l
List all databases hosted on the PostgreSQL server instance
\c <database_name>
Connect / switch to a different database
\dt
List all tables in the current active schema
\d+ <table_name>
Describe table schema, columns, data types, indexes, and foreign keys
\x
Toggle expanded display mode (formats rows vertically like a card for wide tables)
\q
Quit / exit the psql command line client
Backups & Performance
pg_dump -U postgres -d mydb -F c -b -v -f backup.dump
Create high-speed compressed custom-format database backup
pg_restore -U postgres -d mydb -v backup.dump
Restore database from compressed pg_dump file
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM orders;
Profile real query execution time, disk reads, and index scans