PostgreSQL Commands

Large Objects

  • \lo_export LOBOID FILE
  • \lo_import FILE [COMMENT]
  • \lo_list
  • \lo_unlink LOBOID

Misc

- -
\cd [DIR] Change the directory
\timing [on|off] Toggle timing
\! [COMMAND] Execute in shell
\! ls -l List all in shell

Variables

- -
\prompt [TEXT] NAME Set variable
\set [NAME [VALUE]] Set variable (or list all if no parameters)
\unset NAME Delete variable

Input/Output

- -
\copy ... Import/export table See also: copy
\echo [STRING] Print string
\i FILE Execute file
\o [FILE] Export all results to file
\qecho [STRING] String to output stream

Formatting

- -
\a Toggle between unaligned and aligned
\C [STRING] Set table title, or unset if none
\f [STRING] Show or set field separator for unaligned
\H Toggle HTML output mode
\t [on|off] Show only rows
\T [STRING] Set or unset HTML tag attributes
\x [on|off] Toggle expanded output

Connection

- -
\c [DBNAME] Connect to new database
\encoding [ENCODING] Show or set client encoding
\password [USER] Change the password
\conninfo Display information

Informational

- -
\l[+] List all databases
\dn[S+] List schemas
\di[S+] List indexes
\du[+] List roles
\ds[S+] List sequences
\df[antw][S+] List functions
\deu[+] List user mappings
\dv[S+] List views
\dl List large objects
\dT[S+] List data types
\da[S] List aggregates
\db[+] List tablespaces
\dc[S+] List conversions
\dC[+] List casts
\ddp List default privileges
\dd[S] Show object descriptions
\dD[S+] List domains
\des[+] List foreign servers
\dew[+] List foreign-data wrappers
\dF[+] List text search configurations
\dFd[+] List text search dictionaries
\dFp[+] List text search parsers
\dFt[+] List text search templates
\dL[S+] List procedural languages
\do[S] List operators
\dO[S+] List collations
\drds List per-database role settings
\dx[+] List extensions
S: show system objects, +: additional detail

Query buffer

- -
\e [FILE] Edit the query buffer (or file)
\ef [FUNC] Edit function definition
\p Show the contents
\r Reset (clear) the query buffer
\s [FILE] Display history or save it to file
\w FILE Write query buffer to file
Comments