J. Buchmann
J. Buchmann

Reputation: 31

Systemd cannot start Postgresql on Red Hat EL7

On Red Hat EL7, I installed Postgres from the standard repository and initialized the database in the usual way:

# postgresql-setup initdb

But when I try to start the service with:

# systemctl start postgresql.service

I get an error:

Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.

journalctl -xn gives me:

Oct 06 14:52:55 myserver systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit postgresql.service has begun starting up.
Oct 06 14:52:55 myserver systemd[29267]: Failed at step USER spawning /usr/bin/postgresql-check-db-dir: No such process
-- Subject: Process /usr/bin/postgresql-check-db-dir could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The process /usr/bin/postgresql-check-db-dir could not be executed and failed.
-- 
-- The error number returned while executing this process is 3.

Anyone have any ideas?

Upvotes: 0

Views: 4363

Answers (2)

J. Buchmann
J. Buchmann

Reputation: 31

I don't consider this a complete and proper fix, but it's what I'd call a "strong workaround". The problem seems to start with the fact that this Linux system can authenticate locally as well as through a directory server. The PostgreSQL package tries to create a user:group combo called postgres:postgres. The user "postgres" wasn't created because it already exists in the directory server. The group "postgres" was created locally.

When systemd starts Postgres, it changes into the postgres user before trying to call postgresql-check-db-dir which is a script that checks whether the database directory has been intialized with postgresql-setup initdb. It seems that systemd can't change to this directory-supplied postgres user.

My work-around was to create a new local user ("pgsql") and change the ownership of /var/lib/pgsql and /var/run/postgresql to this new user, then create a custom systemd service file called /etc/systemd/system/postgresql.service to override the default one. The contents of this file are:

.include /usr/lib/systemd/system/postgresql.service

[Service]
User=pgsql
Group=postgres

That allows Postgres to be started and stopped by systemd.

Upvotes: 2

rpirsc13
rpirsc13

Reputation: 443

For me the logs are telling you that the db path does not exist. Are you sure psql is configured correctly, the db path exists and you have permission to access it ?

Upvotes: 0

Related Questions