Could not open PID File

Hello. When I try to use pg_ctl (e.g. pg_ctl status /etc/postgresql/17/main), I get the error

pg_ctl: could not open PID file “/var/lib/postgresql/17/main/postmaster.pid”: Permission denied

Can anyone help me?

Have you checked the permissions through the entire directory path? What user are you executing pg_ctl as? Does this user have permissions to the path? Do you have SElinux set to Enforcing?

Hello mathewb. I want to thank you for your response. However, I have no idea how to answer your questions.

Hello @Lupus,
You will need to find someone who is familiar with linux, and the OS distribution you are using. Apologies, but the questions I’ve asked are basic level 101 when troubleshooting permissions in linux.

Hello @Lupus

postmaster.pid pid file is always created inside the Postgresql data directory

Please check postmaster.pid file permission in your environment using the below command and make sure the user you are using to run
ls -l /var/lib/postgresql/17/main/postmaster.pid

Example:

# ls -l /var/lib/pgsql/16/data/postmaster.pid
-rw------- 1 postgres postgres 91 Apr 25 09:03 /var/lib/pgsql/16/data/postmaster.pid

Also, to check status using pg_ctl , the following is the correct syntax.
pg_ctl status [-D DATADIR]

Example:

[postgres@node0 ~]$ /usr/pgsql-16/bin/pg_ctl status -D /var/lib/pgsql/16/data/
pg_ctl: server is running (PID: 6311)
/usr/pgsql-16/bin/postgres "-D" "/var/lib/pgsql/16/data/"

Please check the status using this syntax pg_ctl status [-D DATADIR]

Hello lalit.choudhary. When I try to run ls -l /var/lib/pgsql/17/data/postmaster.pid I get the error

ls: cannot access ‘/var/lib/pgsql/17/data/postmaster.pid’: No such file or directory

Also, when I try to run /usr/pgsql-17/bin/pg_ctl status -D /var/lib/pgsql/17/data/ I get the error

zsh: no such file or directory: /usr/pgsql-17/bin/pg_ctl

Hello, @Lupus

The above error indicates an invalid path of the pg_ctl binary. Also, please check and identify a valid path for the PGDATA directory and use that.

I would suggest working with your PostgreSQL/OS admin to identify installation path of PostgreSQL binaries and PGDDATA file.

Thanks lalit.choudhary. I really appreciate your help.

1 Like

Hi, are you still having issues?

Hello Robert. I have to admit that I am still having problems,

Hi,

Hello Robert. I have to admit that I am still having problems,

Can you list your datacluster “ls -al” and show the results?

  • as root
  • as postgres

Hello Robert. Could you tell me exactly what command(s) to enter.

Hey @Lupus,
You need to contact your DB admins, and get some guidance. Show them this post, and they can help you out with the basics far faster than we can.