psql Essentials
Harry
· 11 Sep 2026
· 9 views
What is psql?
psql is the interactive terminal client for PostgreSQL. It runs SQL and provides handy meta-commands that start with a backslash.
Useful Meta-Commands
\l list all databases
\c appdb connect to database appdb
\dt list tables in current schema
\d customers describe table customers
\dn list schemas
\q quit psql
! column -w or type \? for full helpRunning a File
psql -U app_user -d appdb -f /tmp/seed.sql
Inside psql you can also run \i filename.sql to execute a script.
Settings Worth Knowing
\pset pager off
\timing on
SHOW search_path;\timing on shows how long each query takes; search_path controls which schemas are searched for tables.
Key Points
- Meta-commands beginning with backslash manage the connection and display objects.
- Use
\dto inspect table structure. - Run SQL scripts with
-for\i. - Enable
\timingwhile tuning slow queries.