Search PostgreSQL documentation
PG 18 · Browse by category, or enter a name or keyword
Popular entries9756
\errverbose\errverbose
Repeats the most recent server error message at maximum verbosity, as though VERBOSITY were set to verbose and SHOW_CONTEXT were set to always.psql › Usage › Meta-Commands
\ev\ev [ view_name [ line_number ] ]
This command fetches and edits the definition of the named view, in the form of a CREATE OR REPLACE VIEW command. Editing is done in the same way as for \ed…psql › Usage › Meta-Commands
\f\f [ string ]
Sets the field separator for unaligned query output. The default is the vertical bar (|). It is equivalent to \pset fieldsep.psql › Usage › Meta-Commands
\g\g [ (option=value [...]) ] [ filename ]\g [ (option=value [...]) ] [ |command ]
Sends the current query buffer to the server for execution. If parentheses appear after \g, they surround a s…psql › Usage › Meta-Commands
\gdesc\gdesc
Shows the description (that is, the column names and data types) of the result of the current query buffer. The query is not actually executed; however, if it contains some type of sy…psql › Usage › Meta-Commands
\getenv\getenv psql_var env_var
Gets the value of the environment variable env_var and assigns it to the psql variable psql_var. If env_var is not defined in the psql process's environment, psql_va…psql › Usage › Meta-Commands
\gexec\gexec
Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on…psql › Usage › Meta-Commands
\gset\gset [ prefix ]
Sends the current query buffer to the server and stores the query's output into psql variables (see Variables below). The query to be executed must return exactly one row. E…psql › Usage › Meta-Commands
\gx\gx [ (option=value [...]) ] [ filename ]\gx [ (option=value [...]) ] [ |command ]
\gx is equivalent to \g, except that it forces expanded output mode for this query, as if expanded=on were …psql › Usage › Meta-Commands
\h\h or \help [ command ]
Gives syntax help on the specified SQL command. If command is not specified, then psql will list all the commands for which syntax help is available. If command is an…psql › Usage › Meta-Commands
\i\i or \include filename
Reads input from the file filename and executes it as though it had been typed on the keyboard. If filename is - (hyphen), then standard input is read until an EOF in…psql › Usage › Meta-Commands
\if\if expression\elif expression\else\endif
This group of commands implements nestable conditional blocks. A conditional block must begin with an \if and end with an \endif. In between there m…psql › Usage › Meta-Commands
\ir\ir or \include_relative filename
The \ir command is similar to \i, but resolves relative file names differently. When executing in interactive mode, the two commands behave identically. How…psql › Usage › Meta-Commands
\l\l[x+] or \list[x+] [ pattern ]
List the databases in the server and show their names, owners, character set encodings, and access privileges. If pattern is specified, only databases whose n…psql › Usage › Meta-Commands
\lo\lo_export loid filename
Reads the large object with OID loid from the database and writes it to filename. Note that this is subtly different from the server function lo_export, which acts w…psql › Usage › Meta-Commands
\o\o or \out [ filename ]\o or \out [ |command ]
Arranges to save future query results to the file filename or pipe future results to the shell command command. If no argument is specified, th…psql › Usage › Meta-Commands
\p\p or \print
Print the current query buffer to the standard output. If the current query buffer is empty, the most recently executed query is printed instead.psql › Usage › Meta-Commands
\parse\parse statement_name
Creates a prepared statement from the current query buffer, based on the name of a destination prepared-statement object. An empty string denotes the unnamed prepared s…psql › Usage › Meta-Commands
\password\password [ username ]
Changes the password of the specified user (by default, the current user). This command prompts for the new password, encrypts it, and sends it to the server as an ALT…psql › Usage › Meta-Commands
\prompt\prompt [ text ] name
Prompts the user to supply text, which is assigned to the variable name. An optional prompt string, text, can be specified. (For multiword prompts, surround the text wi…psql › Usage › Meta-Commands
\pset\pset [ option [ value ] ]
This command sets options affecting the output of query result tables. option indicates which option is to be set. The semantics of value vary depending on the sel…psql › Usage › Meta-Commands
\q\q or \quit
Quits the psql program. In a script file, only execution of that script is terminated.psql › Usage › Meta-Commands
\qecho\qecho text [ ... ]
This command is identical to \echo except that the output will be written to the query output channel, as set by \o.psql › Usage › Meta-Commands
\r\r or \reset
Resets (clears) the query buffer.psql › Usage › Meta-Commands
\restrict\restrict restrict_key
Enter "restricted" mode with the provided key. In this mode, the only allowed meta-command is \unrestrict, to exit restricted mode. The key may contain only alphanumer…psql › Usage › Meta-Commands
\s\s [ filename ]
Print psql's command line history to filename. If filename is omitted, the history is written to the standard output (using the pager if appropriate). This command is not ava…psql › Usage › Meta-Commands
\set\set [ name [ value [ ... ] ] ]
Sets the psql variable name to value, or if more than one value is given, to the concatenation of all of them. If only one argument is given, the variable is …psql › Usage › Meta-Commands
\setenv\setenv name [ value ]
Sets the environment variable name to value, or if the value is not supplied, unsets the environment variable. Example: testdb=> \setenv PAGER less testdb=> \setenv LE…psql › Usage › Meta-Commands
\sf\sf[+] function_description
This command fetches and shows the definition of the named function or procedure, in the form of a CREATE OR REPLACE FUNCTION or CREATE OR REPLACE PROCEDURE comma…psql › Usage › Meta-Commands
\startpipeline\startpipeline\sendpipeline\syncpipeline\endpipeline\flushrequest\flush\getresults [ number_results ]
This group of commands implements pipelining of SQL statements. A pipeline must begin wi…psql › Usage › Meta-Commands
\sv\sv[+] view_name
This command fetches and shows the definition of the named view, in the form of a CREATE OR REPLACE VIEW command. The definition is printed to the current query output chann…psql › Usage › Meta-Commands
\t\t
Toggles the display of output column name headings and row count footer. This command is equivalent to \pset tuples_only and is provided for convenience.psql › Usage › Meta-Commands
\timing\timing [ on | off ]
With a parameter, turns displaying of how long each SQL statement takes on or off. Without a parameter, toggles the display between on and off. The display is in millise…psql › Usage › Meta-Commands
\unrestrict\unrestrict restrict_key
Exit "restricted" mode (i.e., where all other meta-commands are blocked), provided the specified key matches the one given to \restrict when restricted mode was ente…psql › Usage › Meta-Commands
\unset\unset name
Unsets (deletes) the psql variable name. Most variables that control psql's behavior cannot be unset; instead, an \unset command is interpreted as setting them to their default v…psql › Usage › Meta-Commands
\w\w or \write filename\w or \write |command
Writes the current query buffer to the file filename or pipes it to the shell command command. If the current query buffer is empty, the most recen…psql › Usage › Meta-Commands
\warn\warn text [ ... ]
This command is identical to \echo except that the output will be written to psql's standard error channel, rather than standard output.psql › Usage › Meta-Commands
\watch\watch [ i[nterval]=seconds ] [ c[ount]=times ] [ m[in_rows]=rows ] [ seconds ]
Repeatedly execute the current query buffer (as \g does) until interrupted, or the query fails, or the executi…psql › Usage › Meta-Commands
\x\x [ on | off | auto ]
Sets or toggles expanded table formatting mode. As such it is equivalent to \pset expanded.psql › Usage › Meta-Commands
\z\z[Sx] [ pattern ]
Lists tables, views and sequences with their associated access privileges. If a pattern is specified, only tables, views and sequences whose names match the pattern are li…psql › Usage › Meta-Commands
More results
Find definitions in the PostgreSQL manuals, reference library, and extension catalogue.
pg17: choose a version ex: extensions only ↑↓ select ↵ open