1

After installing postgres-9.3 via yum in my CentOS 7, its default configuration puts socket in /tmp directory. I have httpd (installed via yum as well) which is by default managed by system.d with PrivateTmp option enabled. This means that any web application running on httpd can't access /tmp so connect to postgres. I have changed postgres configuration so it should put its socket in /var/run/postgres just like in Ubuntu.

Now the problem is, that postgres doesn't have enough privileges to write to /var/run. My first though was to do just:

chown postgres:postgres /var/run/postgres

But /var/run directory is cleaned after reboot so this won't work. My question is:

How to grant access to /var/run/postgres for postgres user in such a way that will persist reboots? I don't want to change socket location and I don't want to change httpd's system.d configuration. I just want postgres to be able to write to /var/run/postgres. Any help is much appreciated.

3 Answers 3

2

Are you sure the socket is only in /tmp on CentOS 7?

Recent versions of Fedora have two copies of the socket, one in /run/postgresql (which is where /var/run/postgresql is really located after links are resolved) which is the preferred version on modern systems, and one in /tmp for legacy clients that expect to find it there.

In any case if you do need to ensure the directory is created at boot then use a tmpfiles.d file, like /usr/lib/tmpfiles.d/postgresql.conf which ships in Fedora and contains:

d /var/run/postgresql 0755 postgres postgres -

1

The directory /var/run is a symbolic link to /run in CentOS 7. The socket directory for PostgreSQL is /run/postgresql. It is a temporary directory, created at boot time.

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. CentOS 7 has the systemd-tmpfiles configuration for PostgreSQL in /usr/lib/tmpfiles.d/postgresql-96.conf. By default, the file contains 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.

1
  • The man page, man tmpfiles.d:freedesktop.org/software/systemd/man/tmpfiles.d.html, explains, notably: "Files in /etc/tmpfiles.d override files with the same name in /usr/lib/tmpfiles.d", which, combined with the fact that /etc/ is a more standard place for configuration files, is why your recommendation makes sense.
    – cazort
    Aug 26, 2021 at 20:28
0

Just put your desired commands in /etc/rc.local file, and they will be executed at the end of each booting process.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .