Wiki / psql Commands
psql Commands
Compare versionsBackslash commands with exact syntax, modifiers, examples and client-version history.
Reading PostgreSQL 18.6.
130 entries; 130 recorded in PostgreSQL 18.6.
-
\syncpipeline Query execution
This group of commands implements pipelining of SQL statements. A pipeline must begin with a \startpipeline and end with an \endpipeline . In between there may be any number of \syncpipeline commands, which sends a sync message without ending the on…
-
\watch Query execution
Repeatedly execute the current query buffer (as \g does) until interrupted, or the query fails, or the execution count limit (if given) is reached, or the query no longer returns the minimum number of rows. Wait the specified number of seconds (defa…
-
\! Scripting and assistance
With no argument, escapes to a sub-shell; psql resumes when the sub-shell exits. With an argument, executes the shell command command .
-
\? Scripting and assistance
Shows help information. The optional topic parameter (defaulting to commands ) selects which part of psql is explained: commands describes psql 's backslash commands; options describes the command-line options that can be passed to psql ; and variab…
-
\cd Scripting and assistance
Changes the current working directory to directory . Without argument, changes to the current user's home directory. For details on how home directories are found, see Section 32.16 .
-
\copyright Scripting and assistance
Shows the copyright and distribution terms of PostgreSQL .
-
\echo Scripting and assistance
Prints the evaluated arguments to standard output, separated by spaces and followed by a newline. This can be useful to intersperse information in the output of scripts. For example:
-
\elif Scripting and assistance
This group of commands implements nestable conditional blocks. A conditional block must begin with an \if and end with an \endif . In between there may be any number of \elif clauses, which may optionally be followed by a single \else clause. Ordina…
-
\else Scripting and assistance
This group of commands implements nestable conditional blocks. A conditional block must begin with an \if and end with an \endif . In between there may be any number of \elif clauses, which may optionally be followed by a single \else clause. Ordina…
-
\endif Scripting and assistance
This group of commands implements nestable conditional blocks. A conditional block must begin with an \if and end with an \endif . In between there may be any number of \elif clauses, which may optionally be followed by a single \else clause. Ordina…
-
\errverbose Scripting and assistance
Repeats the most recent server error message at maximum verbosity, as though VERBOSITY were set to verbose and SHOW_CONTEXT were set to always .
-
\getenv Scripting and assistance
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_var is not changed. Example:
-
\h Scripting and assistance
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 asterisk ( * ), then syntax help on all SQL commands is shown.
-
\help Scripting and assistance
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 asterisk ( * ), then syntax help on all SQL commands is shown.
-
\i Scripting and assistance
Reads input from the file filename and executes it as though it had been typed on the keyboard.
-
\if Scripting and assistance
This group of commands implements nestable conditional blocks. A conditional block must begin with an \if and end with an \endif . In between there may be any number of \elif clauses, which may optionally be followed by a single \else clause. Ordina…
-
\include Scripting and assistance
Reads input from the file filename and executes it as though it had been typed on the keyboard.
-
\include_relative Scripting and assistance
The \ir command is similar to \i , but resolves relative file names differently. When executing in interactive mode, the two commands behave identically. However, when invoked from a script, \ir interprets file names relative to the directory in whi…
-
\ir Scripting and assistance
The \ir command is similar to \i , but resolves relative file names differently. When executing in interactive mode, the two commands behave identically. However, when invoked from a script, \ir interprets file names relative to the directory in whi…
-
\prompt Scripting and assistance
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 with single quotes.)
-
\q Scripting and assistance
Quits the psql program. In a script file, only execution of that script is terminated.
-
\qecho Scripting and assistance
This command is identical to \echo except that the output will be written to the query output channel, as set by \o .
-
\quit Scripting and assistance
Quits the psql program. In a script file, only execution of that script is terminated.
-
\restrict Scripting and assistance
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 alphanumeric characters.
-
\set Scripting and assistance
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 set to an empty-string value. To unset a variable, use the \unset command.
-
\setenv Scripting and assistance
Sets the environment variable name to value , or if the value is not supplied, unsets the environment variable. Example:
-
\timing Scripting and assistance
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 milliseconds; intervals longer than 1 second are also shown in minutes:seconds format, …
-
\unrestrict Scripting and assistance
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 entered.
-
\unset Scripting and assistance
Unsets (deletes) the psql variable name .
-
\warn Scripting and assistance
This command is identical to \echo except that the output will be written to psql 's standard error channel, rather than standard output.
RecordedFirst recordedInterface or attribute changeNo longer recorded
Squares indicate presence in sampled builds, not first introduction. Select a square for the same-version definition and sources.
Changes in PostgreSQL 18.6 · Export JSON
Reading this collection
The selected version is the psql client build. Backslash commands are case-sensitive: for example, \dD and \dd are different commands. Related command spellings can share a documented syntax block.