psql Cheatsheet
Cheatsheet for psql, the command line client for PostgreSQL.
Launch
Do:
# Interactive
PGPASSWORD=thepassword psql -h localhost -p 5432 -U postgres -d postgres
# Launch a SQL script
PGPASSWORD=thepassword psql -h localhost -p 5432 -U postgres -d postgres -f 010-db-set-up.sql
Metacommands
Make your like easier.
Command | Usage |
---|---|
! command | Issue a shell command to the underlying shell. |
! | Opens a shell session. exit returns to the psql prompt. |
\cd | Change working directory. |
\i file | Executes script file. |
\o file | Outputs results to file. Use \qecho to annotate. \o returns to the standard output. |
\o /dev/null | Cancel all outputs. |
\o | Restore normal output. |