'Postgresql failed to start. Reboot is resetting the permission given to /var/run/postgresql/

FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.1111.lock": Permission denied
psql: could not connect to server: Connection refused
        Is the server running on host "S01B01" (10.10.222.193) and accepting
        TCP/IP connections on port 1111?

Could you please help me in getting a permanent fix for this.

postgresql.conf:

data_directory = '/apps/ins/router/pgdata'

hba_file = '/apps/ins/router/pgdata/pg_hba.conf'

pg_hba.conf:

host     all             ins        10.10.10.10    255.255.255.255    trust
host     all             ins        127.0.0.1      255.255.255.255    trust


Solution 1:[1]

Both socket directories for PostgreSQL (/run/postgresql and /var/run/postgresql) are temporary directories created at boot time. (The /var/run/postgresql is in fact usually a symbolic link to /run/postgresql).

With the advent of systemd, a new mechanism called systemd-tmpfiles has been introduced to manage 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.

Check those configuration directories for PostgreSQL configuration, usually postgresql.conf. (You will most likely find it at /usr/lib/tmpfiles.d/postgresql.conf.) The file will contain something like the following line:

d /run/postgresql 0755 postgres postgres -

You can change permissions, owner and group by editing that line. The recommended way to make such changes, however, is not to directly edit files under /usr/lib/tmpfiles.d/, but to copy configuration files over to /etc/tmpfiles.d/, and make the necessary changes in that copy instead.

Solution 2:[2]

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';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Anil Agrawal