(5.2+) PostgreSQL does not start with systemd commands

Troubleshooting scenario

Note: This guide only applies to RHEL 8.4.

When SELINUX policies are enforced on an IVG server, the PostgreSQL (postgresqld) service may failed to start up. In this case, you may see an error message similar to the following:

Unit postgresqld.service has begun starting up.
Feb 04 02:26:51 lab.vht.com systemd[50564]: postgresqld.service: Failed to execute command: Permission denied
Feb 04 02:26:51 lab.vht.com systemd[50564]: postgresqld.service: Failed at step EXEC spawning /export/home/postgres-ivg/12/>
-- Subject: Process /export/home/postgres-ivg/12/bin/pg_ctl could not be executed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The process /export/home/postgres-ivg/12/bin/pg_ctl could not be executed and failed.
--
-- The error number returned by this process is 13.
Feb 04 02:26:51 lab.vht.com systemd[1]: postgresqld.service: Control process exited, code=exited status=203
Feb 04 02:26:51 lab.vht.com systemd[1]: postgresqld.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The unit postgresqld.service has entered the 'failed' state with result 'exit-code'.
Feb 04 02:26:51 hvp03.vhtlab.vhtcx.com systemd[1]: Failed to start PostgreSQL 12 database server.

Resolution

This can be resolved by executing a user-level systemd script, which is the recommend method of executing user-specific binaries (which can be a factor in this scenario).

Use the following steps to start, stop, restart, or check the status of the postgresqld service:

  • Login to PostgreSQL server
su - <postgres-user-name>
  • Run the required commands for start/stop/status/restart:
systemctl --user status postgresqldsystemctl --user start postgresqldsystemctl --user stop postgresqldsystemctl --user restart postgresqld