3

By default, my PostgreSQL installation was creating a socket in /tmp but my psql command-line client was looking in /var/run/postgresql/.s.PGSQL.5432.

To remedy this, I edited postgresql.conf and changed the directory to

unix_socket_directories = '/var/run/postgresql/'

Unfortunately, there is by default, no postgresql directory in the var/run directory. So, I created it and started the server, and it all worked well. As soon as I shutdown and restart the server, for some reason the /var/run/postgresql directory disappears. This causes the startup of postgres to crash with an error:

FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": No such file or directory

Help appreciated!

1 Answers1

1

Solution 1 (By managing temporary directory /run/postgresql, /var/run/postgresql)

Directory /run/postgresql is a temporary directory. Path /var/run/postgresql is usually a symbolic link to /run/postgresql.

systemd-tmpfiles is mechanism to manage such temporary files and directories. systemd-tmpfiles creates temporary directories during boot and sets their owner, group and permissions. It may read configuration files in three different locations. Files in /etc/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d and /run/tmpfiles.d.

We can create directory /run/postgresql on the fly at boot time using systemd-tmpfiles mechanism by creating postgresql configuration file as below

echo "d /run/postgresql 0755 postgres postgres -" > /usr/lib/tmpfiles.d/postgresql.conf

Solution 2 (By relocating PostgreSQL lock file location)

Another way to fix the issue is to relocate the PostgreSQL lock file location. We can do so by using below query

ALTER SYSTEM SET unix_socket_directories='<any-existing-path-with-valid-permissions>, /tmp';

Here we can provide any path for PostgreSQL lock file which is already present on the system and have required permissions to manage lock files by postgres user.