Tab completion makes it easy to change psql settings interactively, removing the need to memorize options or spend time searching through documentation.
Realizing these builtin cheatsheets are always at my fingertips has improved my productivity in psql tremendously.
Enter \? variables
in psql for help with psql variables.
Or enter \? v<TAB>
and let tab completion finish the word.
Most of the options that can be specified when launching psql can also be changed while it’s running, using either the \pset
or \set
meta-commands.
To list display options, enter \pset <TAB><TAB>
:
For display settings (but not other options), enter an option without a value to see its current setting.
Some settings also have completions for valid values:
Other psql options are stored in “specially treated” variables which can be changed with \set
.
By convention, psql variables in upper case are used by psql, not of all which can be changed. Depending on your psql configuration, completions might include lower case variables used for other purposes as well.
Enter \set <TAB><TAB>
to see completions for psql variables:
Some variables also have completions for valid settings:
Unlike \pset
, if you don’t provide a value for an option, it will be reset to the default. For example, to restore AUTOCOMMIT
to its default value of on
:
\set AUTOCOMMIT
Setting a PROMPT
variable to nothing will not restore the default prompt.
Was experimenting with the prompt in psql and wondered if setting PROMPT1 to nothing would reset it to the default.
— PostgreSQL Stan (@PostgresqlStan) January 30, 2023
😂 pic.twitter.com/6lepT3PxkX
Tab completion on Windows: Tab completion is not available for psql on Windows but reportedly works for psql running on WSL (Windows Subsystem for Linux).