What are the most useful psql meta-commands?

BeginnerHands-onPostgreSQL
Answer

Short answer

psql's backslash commands let you explore without writing SQL: \l (databases), \c (connect), \dt (tables), \d table (describe), \du (roles), \dn (schemas), \di (indexes), \x (expanded output), \conninfo, \timing, \q (quit).

Cheat sheet

Command Shows
\l All databases with owner and encoding
\c shop Switch to database shop
\dt / \dt+ Tables (+ sizes)
\d orders Columns, types, indexes, constraints of a table
\di Indexes
\dn Schemas
\du Roles and attributes (Superuser, Create DB…)
\dx Installed extensions
\conninfo Current database, user, host, port
\x Toggle vertical output for wide rows
\timing Show how long each query takes
\e Edit the last query in your editor
\? Help for all meta-commands

Tip

Run psql with -E to see the SQL behind meta-commands — handy for learning the system catalogs.

What to say in the interview

"\l, \c, \dt, \d, \du and \dn cover most exploration; \x for wide rows, \timing for performance, \conninfo to confirm where I'm connected — especially important before running anything on production."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL