Unable to start postgresql service on CentOS 7
Solution 1
Make sure you have installed all packages correctly and updated yum repository sections [base]
and [updates]
before installation as it mentioned in the guide . We have CentOS 7 with PostgreSQL 9.5 and it works perfectly fine with following steps:
vi /etc/yum.repos.d/CentOS-Base.repo
yum localinstall http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
yum list postgres*
yum install -y postgresql95-server.x86_64 postgresql95-contrib.x86_64 postgresql95-libs.x86_64
/usr/pgsql-9.5/bin/postgresql95-setup initdb
systemctl enable postgresql-9.5.service
systemctl start postgresql-9.5.service
and finally, systemctl status postgresql-9.5.service
should show you something like this:
postgresql-9.5.service - PostgreSQL 9.5 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled)
Active: active (running) since Fri 2016-02-19 00:01:13 UTC; 6min ago
Process: 10809 ExecStart=/usr/pgsql-9.5/bin/pg_ctl start -D ${PGDATA} -s -w -t 300 (code=exited, status=0/SUCCESS)
Process: 10802 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 10811 (postgres)
CGroup: /system.slice/postgresql-9.5.service
├─10811 /usr/pgsql-9.5/bin/postgres -D /var/lib/pgsql/9.5/data
├─10812 postgres: logger process
├─10814 postgres: checkpointer process
├─10815 postgres: writer process
├─10816 postgres: wal writer process
├─10817 postgres: autovacuum launcher process
└─10818 postgres: stats collector process
Solution 2
The most common issue is that the database cluster was not initialized. You can initialize it easily by running the postgresql-XX-setup script with the initdb
command, e.g.
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
Then start the Postgres service, e.g.
sudo systemctl start postgresql-11
Muthu Palanisamy
Updated on October 20, 2021Comments
-
Muthu Palanisamy over 2 years
Unable to start postgresql-9.5 on CentOS 7.
I followed this page - https://wiki.postgresql.org/wiki/YUM_Installation - for installing the database server on CentOS.
I tried the same after setting
setenforce 0
, and that did not help either.I am doing all operations as
root
.systemctl start postgresql-9.5.service Job for postgresql-9.5.service failed because the control process exited with error code. See "systemctl status postgresql-9.5.service" and "journalctl -xe" for details.
And here is what I get for status -
Redirecting to /bin/systemctl status postgresql-9.5.service ● postgresql-9.5.service - PostgreSQL 9.5 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2016-02-18 15:20:30 EST; 2min 28s ago Process: 15041 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE) Feb 18 15:20:30 myserver systemd[1]: Starting PostgreSQL 9.5 database server... Feb 18 15:20:30 myserver systemd[1]: postgresql-9.5.service: control process exited, code=exited status=1 Feb 18 15:20:30 myserver systemd[1]: Failed to start PostgreSQL 9.5 database server. Feb 18 15:20:30 myserver systemd[1]: Unit postgresql-9.5.service entered failed state. Feb 18 15:20:30 myserver systemd[1]: postgresql-9.5.service failed.
And the contents of the different conf files are as follows -
[root@myserver /]# cat /etc/ld.so.conf.d/postgresql-pgdg-libs.conf /usr/pgsql-9.5/lib/ [root@myserver /]# cat /usr/lib/tmpfiles.d/postgresql-9.5.conf d /var/run/postgresql 0755 postgres postgres - [root@myserver /]# cat /usr/pgsql-9.5/share/postgresql-9.5-libs.conf /usr/pgsql-9.5/lib/ [root@myserver /]# cat /etc/alternatives/pgsql-ld-conf /usr/pgsql-9.5/lib/ [root@myserver /]# cat /var/lib/alternatives/pgsql-ld-conf auto /etc/ld.so.conf.d/postgresql-pgdg-libs.conf /usr/pgsql-9.5/share/postgresql-9.5-libs.conf 950
Googled for the error that I am seeing. A number of folks have seen the same error, and the underlying cause is different in each case. Reading through those posts, it is not clear that I am seeing any of the already reported causes.
-
Muthu Palanisamy about 8 yearsThe magic line was this -
# /usr/pgsql-9.5/bin/postgresql95-setup initdb
. Thanks :). The guide mentions the above line as an alternate, ifservice <name> initdb
did not work. However, there is no guidance on what the output would look like if it did work. In my case, I usedservice <name> initdb
and it just returned me back to the command prompt. And which I eventually found out, that it did not work. -
Sabarish over 7 yearsperfect..exactly what i wanted
-
Anurag Singh over 6 yearsFor me the magic lines were-[ /usr/pgsql-9.5/bin/postgresql95-setup initdb] and [systemctl enable postgresql-9.5.service]
-
Lama about 6 yearsIn my case the initdb-script was executed by a non-root user (postgresql user). The script will create a folder 'pg_log' within the $PGDATA folder before it quits without doing anything else. After I deleted everything from the data folder I was able to execute initdb as root and everything was working fine. (deleting from data/ will only make sense if you can restore data or if your setup is quite new ;) )