There are several options for the location of the system-wide :
somewhere in , i.e., in
in the PostgreSQL installation directory or one of its subdirectories.
in the location denoted by the env var or the env var .
the location returned when running . Note that not all PostgreSQL
installations include .
The location of the user-specific is by default .
On startup, tries to read the system-wide , then the user-specific
, if the user-specific exists. Statements in the user-specific
have priority over statements in the system-wide .
All variables in have sane default values.
The PostgreSQL documentation lists some variable that “are treated specially by psql”. For some of these vars,
the value can be set, i.e. for the vars:
HISTCONTROL
HISTFILE
PROMPT1, PROMPT2, PROMPT3
…
For some of these vars, the value can’t be set, or it doesn’t make sense to set the value of these vars:
HOST
DBNAME
PORT
USER
…
If the value of the variable is to be used to set the value of another psqlrc var, the var must be prepended
with the colon
, i.e.:
\set HISTFILE ~/.state/psql/psql_history-:DBNAME
configuring the location of psql_history
The default location of this file is . Location and name of the psql history file can
be configured either with
For user bob, connected to database sampledb by a socket, the resulting prompt will look like this:
bob@[local]:5432:sampledb #
with the prompt in blue foreground color on the terminals default background color. The prompt display items are:
%n session username
%m database server’s hostname up to the first dot –- is if the connection is over a Unix domain socket
%> listening port
%/ current database
%# whether you’re a superuser (#) or a regular user (>)
%x transaction status – usually blank unless in a transaction block (*)
configuring display expansion
can displaying the result of a command in two modes:
normal mode – the layout is horizontal. I.e., for a row-set, the columns of the rows are laid out horizontally.
expanded mode – the layout is vertical. I.e., for a row-set, the columns of the rows are laid out vertically.
The expanded mode is useful to display single a single row with lots of columns. I do not find expanded mode to be useful
for a result with lots of rows or for the result of .
configuring the editor
picks up the editor to use from the env vars
, , and . The env vars are evaluated in
the order listed here. The first env var which is set is used for editing with the
command.
The env var for the editor can be set in the with , i.e.
.
configuring the display of null
By default, null values are not displayed in psql output. This means that in the output, the value NULL can not be
distinguished from empty strings. The display of NULL can be changed with , i.e.:
\pset null (NULL)
works with anything that is utf-8 compatible, including emojis 🙂
In my psqlrc (see above) I use the ghost emoji.
disabling the psql history file to prevent security scrawl
The psql history may contain sensitive information like a user’s password. To prevent the leaking of such sensitive
information, the psql history file can be disabled by