Strange PostgreSQL behaviour on service start 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

&quot;creation of lock file &quot;postmaster.pid&quot; failed: Permission denied&quot;.

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?
Ok, i understood.
It was a &quot;problem&quot; of selinux.
I changed the data directory, and selinux &quot;didn't know&quot; it, so i
chcon -R -t postgresql_db_t /data/pgdata
restorecon -RFv /data/pgdata.