Database Reference
In-Depth Information
Each set command should be on a single line. For example, the
qstats92 statements in Example 3-2 should be all on the same line.
We had to break it into multiple lines to fit the printed page.
When you launch psql now, you'll see the results of executing the startup file:
Null display is "NULL".
Timing is on.
Pager is always used.
psql (9.3.2)
Type "help" for help.
postgres@localhost:5442 postgresql_book#
Some commands work only on Linux/Unix systems, not on Windows, and vice versa.
In either OS, you should use the Linux/Unix slash (solidus) for path to distinguish it
from the forward slash used for options. If you want to start psql bypassing psqlrc , use
the -X option.
To remove a configuration variable or set it back to the default, issue the \unset com‐
mand followed by the variable name, as in: \unset qstat92 .
We'll cover popular psql configuration settings. Even if you don't add them to your psqlrc
file, you can still set them during your session on an as-needed basis. You can find more
examples at psqlrc File for DBAs and Silencing Commands in .psqlrc .
Custom Prompts
If you spend your waking hours playing with psql and you connect to multiple servers
and databases, chances are you'll be switching among them using \connect . Custom‐
izing your prompt to show which server and database you're connected to will enhance
your situational awareness and avoid disaster. In our example psqlrc file, we set our
prompt as follows:
\set PROMPT1 '%n@%M:%>%x %/# '
This includes who we are logged in as ( %n ), the host server ( %M ), the port ( %> ), the
transaction status ( %x ), and the database ( %/ ). This is probably overkill, so economize
as you see fit. The complete listing of prompt symbols is documented in the psql Ref‐
erence Guide .
When we connect with psql to our database, our prompt looks like:
postgres@localhost:5442 postgresql_book#
If we change to another database with \connect postgis_book , our prompt changes
to:
postgres@localhost:5442 postgis_book#
Search WWH ::




Custom Search