I have installed postgres from pacman repo on Manjaro but am running into trouble trying to get it to start.

I have followed the instructions from the arch wiki and have created my db. initdb -D /var/lib/postgres/data/

I run the following command but doesn't complete. pg_ctl -D /var/lib/postgres/data/ -l logfile start

The logfile error is FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory

Could someone please explain what this error means and how I can get Postgres to start?


3 Answers 3


I have followed the instructions from the arch wiki and have created my db.
initdb -D /var/lib/postgres/data/

The /run/postgresql directory does not exist at this point because it's created by the last step of the instructions that you probably overlooked:

Finally, start and enable the postgresql.service.

which means to run systemctl start postgresql and systemctl enable postgresql

What is misleading is this last part of the output from initdb:

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgres/ -l logfile start

This advice must be ignored when you're using systemctl to manage postgresql as a system service. It is the system service that will take care of creating /run/postgresql with the proper permissions and then run the pg_ctl command with the proper arguments and paths.

  • was exactly that combined with my tired mind trying to run systemctl as the postgres user
    – el_oso
    Feb 15, 2021 at 21:37

When systemd is used, it is specifically systemd-tmpfiles that takes care of creating /run/postgresql and setting permissions on it.

The systemd-tmpfiles service is part of systemd, and it is responsible for creating and deleting temporaray and volatile files (in /run, /var/run, /tmp, /var/tmp etc.). The service is started during boot. You may want to check the man page for tmpfiles.d for more details.


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.

You must log in to answer this question.

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