Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: .psql_history to /dev/null

Rather than apply a \set HISTFILE command for every possible connection, we would like to have no .psql_history at all. However, psql seems to dislike that:

% ln -s /dev/null ~/.psql_history
% psql
psql (8.4.8)
postgres=# select version();
...
postgres=# \q
could not save history to file "~/.psql_history": Not owner

There are folks out there willing to patch the source to get a fix but we prefer to be on a vanilla binary installation whenever possible: to us, this isn't worth the hack.

To clarify: we don't want anything kept in this default filename, regardless of whether or not the user on this machine remembers (or knows) what options to pass.

Any suggestions?

like image 515
Joe Creighton Avatar asked Feb 22 '26 21:02

Joe Creighton


1 Answers

You can use -n (or synonym --no-readline) switch in psql command:

Do not use readline for line editing and do not use the history. This can be useful to turn off tab expansion when cutting and pasting.

EDIT:

As another way you can create ~/.psqlrc file that contains \set HISTFILE /dev/null. With that psql doesn't create unwanted .psql_history file at all.

like image 54
Grzegorz Szpetkowski Avatar answered Feb 25 '26 13:02

Grzegorz Szpetkowski