Cheat Sheet
The commands you keep forgetting, with a one-line description and a real example you can copy - 384 across 26 tools. Pick a tool in the sidebar, or search across all of them.
psql (Postgres)
The PostgreSQL command-line client - connect, inspect, and run SQL.| Command | What it does | Example |
|---|---|---|
psql connect | Connect to a database. | psql -h localhost -U postgres -d mydb |
psql (URL) | Connect with a connection string. | psql postgresql://ana:secret@localhost:5432/mydb |
\l | List databases. | \l |
\c | Switch to another database. | \c mydb |
\dt | List tables. | \dt |
\d | Describe a table (columns, indexes). | \d users |
\dn | List schemas. | \dn |
\du | List roles / users. | \du |
\x | Toggle expanded (row-per-column) output. | \x |
\timing | Show how long each query takes. | \timing |
\i | Run SQL from a file. | \i seed.sql |
\copy | Import/export a table as CSV. | \copy users TO 'users.csv' CSV HEADER |
\e | Edit the current query in your $EDITOR. | \e |
\q | Quit psql. | \q |