Part 01 / Topic 10 of 10
The psql survival kit
Ten commands cover 95% of daily psql life. You met several already; here is the full kit:
| Command | What it does |
|---|---|
\q |
Quit psql |
\l |
List databases |
\c name |
Connect to database name |
\dt |
List tables in the current database |
\d name |
Describe table name: columns, types, constraints |
\x |
Toggle expanded output — wide rows print as label: value lines |
\timing |
Toggle showing how long each query took |
\h INSERT |
Help on SQL syntax (any statement) |
\? |
Help on psql's own \ commands |
\i file.sql |
Run SQL statements from a file |
\x earns its place the first time a wide row wraps into soup. Expanded output prints one column per line:
\x
SELECT * FROM customers WHERE customer_id = 1;
Expanded display is on.
-[ RECORD 1 ]-----------------
customer_id | 1
first_name | Asha
last_name | Verma
email | [email protected]
city | Pune
signup_date | 2025-01-05
Run \x again to toggle back to normal tables. \i runs a file — it is how you will run the course's exercise solutions:
shopdb=# \i solutions/ex01.sql
Two non-command survival tricks: the up arrow brings back your previous statements so you never retype, and Tab completes table and column names.
🧪 Quick quiz — answer from memory, then check.
- Which command shows a table's columns and types?
- A row with many columns is unreadable in the terminal. Which command fixes that?
Show the answers
\d table_name(and\dtlists all tables).\x— expanded output, one column per line. Run it again to toggle back.
Done here? The practice set for Part 1 — 6 exercises with solutions — is on the part page.