I'm using .psqlrc file to set my preferable environment in psql. But I got lately annoyed by it confirming the changes every time I run psql:
Basically my .psqlrc looks like this:
\pset null '[null]' \set PROMPT1 '(%n@%M:%>) %`date +%H:%M:%S` [%/] \n%x%# ' \set PROMPT2 '' \set HISTFILE ~/.psql_history- :DBNAME \timing \pset pager always
It sets display of nulls from empty string to [null], which is (for me) more readable. It also changes prompt, so it's a bit more useful.
Additionally it makes psql store history of commands in separate files for each database I'm connecting to. It's a very cool feature, as I connect to many different databases, which share nothing between them, so there is no point to get mailsystem-db related queries in history when I'm connected to sales database.
Last two lines turn on timing of queries, and forces psql to always use pager (which is less, modified to be more helpful, thanks to Merlin Moncure blogpost).
The problem with this psqlrc, is that whenever I start psql, I get this:
=> psql Null display is "[null]". Timing is on. Pager is always used. psql (8.4devel) Type "help" for help.
First three lines are from my .psqlrc, and they were quite annoying. It's nothing wrong when you see them once. Twice. But after 100-th times, you become to hate them.
Today I decided that I'll get rid of them, or at least I'll file a feature request to add some kind of “quiet" switch for psql.
Fortunately, before I sent my request, I checked manual for psql. And in there I found:
This variable is equivalent to the command line option -q. It is probably not too useful in interactive mode.
Great. So I changed my psqlrc to:
\set QUIET 1 \pset null '[null]' \set PROMPT1 '(%n@%M:%>) %`date +%H:%M:%S` [%/] \n%x%# ' \set PROMPT2 '' \set HISTFILE ~/.psql_history- :DBNAME \timing \pset pager always \set QUIET 0
And tested it:
=> psql psql (8.4devel) Type "help" for help.
I know it's not a new feature. Most probably you already knew about it, but I'm so happy with these 3 lines being gone, that I decided to write about it – maybe somebody else also has this issue.