'Tired of creating /run/postgresql and setting read and execute writes after every reboot
I'm running Arch Linux, I installed PostgreSQL as any other arch package. I'm running postgres with a local database located in my user directory. (postgres -D /home/user/data/
) When I do so, I get the error FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
. Creating the directory /run/postgresql and giving the postgres user access solves this problem
$ sudo mkdir /run/postgresql
$ sudo chmod a+w /run/postgresql
however I'm tired of writing these commands every time I reboot, as /run gets cleared when rebooting. I could write a script to execute these commands, but I feel like I'm doing this the wrong way to begin with. Is there any way I could let postgres create its directory itself, or maybe have it not use /run/postgres for it's lock files in the first place?
Solution 1:[1]
Postgres creates the lock file in /run/postgresql
by default.
From the manpage:
-k directory Specifies the directory of the Unix-domain socket on which postgres is to listen for connections from client applications. The default is normally /run/postgresql, but can be changed at build time.
Use -k directory
to tell postgres to use a different directory.
Run your command as postgres -k /tmp -D /home/user/data/
.
Solution 2:[2]
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.
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 | alvits |
Solution 2 | Anil Agrawal |