Postgresql – Strange PostgreSQL behaviour on service start

centospostgresql

Centos 8.3, postgresql 12 (i tried even 10, same thing).

I have set
the permission of the data directory to postgres:postgres. If I start
the service from systemctl, it gives me the error message

"creation of lock file "postmaster.pid" failed: Permission denied".

If I copy the command from postgresql.service which is postmaster -D /data/pgdata and I run from the console as postgres user, it works, and the postmaster.pidfile is correctly created.

I have no ideas, because it's not a permission problem…

What am I missing?

Best Answer

Ok, i understood.

It was a "problem" of selinux.

I changed the data directory, and selinux "didn't know" it, so i

chcon -R -t postgresql_db_t /data/pgdata

restorecon -RFv /data/pgdata.