On Arch Linux, after running the initdb command, I get the following message:

Success. You can now start the database using:
    pg_ctl -D /var/lib/postgres/data -l logfile start

As postgres user I attempt to start by using command above and get and error:

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

I exit to postgres user and attempt to start by the command above and get:

pg_ctl: could not open PID file "/var/lib/postgres/data/postmaster.pid" : Permission denied

Than I try the above command ran as sudo:

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

and get:

pg_ctl: cannot run as root.
  • Check ownership on /var/lib/postgres/. It may be as in the same issue as in this old bug - bugs.archlinux.org/task/16507 – Elvis Plesky Feb 28 '18 at 6:09
  • What is your OS distribution? What is your postgresql server version? Why not just start it using a command like /etc/init.d/postgresql start, service postgresql start? – Khaled Feb 28 '18 at 8:53
  • Arch Linux, in WSL – user1135541 Feb 28 '18 at 20:44

When starting postgres manually, that is without using the packaged startup script, you need to do what the script does:

  1. create the /run/postgresql directory with write permission for postgres and read permission for others. /run is typically mounted on a ram disk so it's normal that it's empty.

  2. run pg_ctl as the user postgres exclusively. Use sudo -u postgres if sudo has to be used for that.

The first error you mention is solved by #1 and the two others are solved by #2. Or just use the startup script that comes with the package for your OS, it's there to take care of these details so you don't have to learn them.

The doc at https://wiki.archlinux.org/index.php/PostgreSQL tells to:

Finally, start and enable the postgresql.service.

which would mean systemctl enable postgresql.service and systemctl start postgresql.service, as opposed to pg_ctl [...options...] start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.