psql Cheatsheet

Top commands.

Connecting

psql connections are where security and ergonomics meet. Get the URL form and .pgpass right; the rest follows.

Inspecting structure

The backslash commands are the daily inspection surface. \dt, \d, \df cover most reads.

Query patterns

Query patterns are the ergonomics layer. Timing, expanded output, EXPLAIN ANALYZE.

Admin queries

Admin queries are the operational surface. pg_stat_activity, pg_locks, pg_stat_user_tables.

Scripting

Scripting psql is its own discipline. Single-shot, file, CSV all map to different shell needs.