Messing with unix_socket_directories is a bad idea
“Hell is paved with good intentions.” - Samuel Johnson
Sometimes you come across an overachiever. Someone that thinks very highly of himself but keeps on inventing new ways to shackle you.
Idea of the day : let’s cut down the number of entries in the unix_socket_directories entry of postgresql.conf, specifically /tmp folder.
Alright now, PostgreSQL might not be the smartest ever when it comes to managing .sock files for local connections.
BUT…
If you remove the /tmp
option in postgresql.conf unix_socket_directories, you will end up with this nice message from PostgreSQL when connecting :
[postgres@server ~]$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Well now you have to provide psql with either
psql -h localhost
or
psql -h /var/run/postgresql
for example. This depending on what you find in your unix_socket_directories parameter.
So just keep the /tmp in your entry.
WHY ?
It’s the best way to insure the folder /tmp is emptied on each reboot so it’s always squeaky clean.
And above all : PostgreSQL always tries to connect only using this folder by default.
Removing entries will not help security. Other things can. Keep at least /tmp
. For us DBAs. Please. This is me being polite. Or at least I am doing my best.
unix_socket_directories = '/var/run/postgresql, /var/postgres/test/9.6/run, /tmp'