psql Meta-Commands: \dt, \d, \l, \du
psql -c "\dt" lists tables; the backslash meta-commands describe the database without writing SQL.
psql ships shortcuts for inspecting a schema: \dt lists tables, \d describes one, \l lists databases, \du lists roles. They run non-interactively through -c, which makes them useful assertions in CI.
What it does
Meta-commands are client-side shortcuts that psql translates into catalog queries. \dt lists tables in the current schema, \d <table> shows its columns and indexes, \l lists databases on the server, and \du lists roles. They are not SQL, so they only work inside psql, not through a generic driver.
Common usage
# list tables (confirm a migration created them)
psql -h db -U app -d appdb -c "\\dt"
# describe one table
psql -h db -U app -d appdb -c "\\d users"
# list databases and roles
psql -h db -U postgres -c "\\l"
psql -h db -U postgres -c "\\du"Options
| Meta-command | What it does |
|---|---|
| \dt | List tables in the current schema |
| \d <name> | Describe a table, view, index, or sequence |
| \l | List databases on the server |
| \du | List roles (users) and their attributes |
| \dn | List schemas |
| \dt+ | List tables with size and description |
In CI
Use psql -c "\dt" after a migration step to confirm the expected tables exist. In a shell that eats backslashes, quote them carefully (double backslashes in a double-quoted heredoc, single in single quotes). For machine parsing, prefer real catalog SQL against information_schema over meta-commands.
Common errors in CI
"Did not find any relations." from \dt means the migration did not run or ran against a different database; check -d. "invalid command \dt" usually means the backslash was stripped by the shell before psql saw it; adjust quoting. Meta-commands sent through a non-psql client are rejected because they are a psql feature, not SQL.