How to change the default unix socket location from /tmp for PostgreSQL
14 Nov 2015
The sort answer is: don't do it. But, many distros do, so if you are trying to mimick a distro build, you may have to.
If custom compiling, you can tell all the binaries by editing
src/include/pg_config_manual.h, so that all the binaries you compile will get this setting.
To change just the server setting at run time, edit
postgresql.conf like so:
unix_socket_directory = '/var/run/postgresql'
Also, you will need to be sure
/var/run/postgresql actually exists between reboots.
In systemd, that would go something like this:
/etc/systemd/system/postgresql.service in your favorite text editor and add this
# create /var/run/postgresql, which disappears between reboots RuntimeDirectory=postgresql