How to Start Postgresql Service on Centos 7

Unable to start postgresql service on CentOS 7

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

Not able to start PostgreSQL

As the echo $PGDATA shows you have PG9.3 as well. Which means that 9.2 service will not start because the port 5432 might be already occupied by postgres 9.3
Do the following

ps- ef | grep postgres 

And get the postgres process id and kill all postgres processes.

Remove the 9.3 data directory using

rm -rf /var/lib/pgsql/9.3

Go to /usr/pgsql-9.2/bin and run the initdb using below command

./postgresql92-setup initdb

After that start the postgresql-9.2 service using

systemctl start postgresql-9.2.service

Unable to start postgresql.service?

Finally, I figured this one out. There was already a file present

/usr/lib/systemd/system/postgresql-9.6.service

So, may be due to the presence of this file, I was not able to start postgresql.service. Then I tried to start postgresql-9.6.service as follows:

[code_master5@BitBox ~]$ sudo systemctl start postgresql-9.6.service
Failed to start postgresql-9.6.service: Unit postgresql-9.6.service not found.

And, as you can see the output, again it failed.

I simply deleted the file using sudo as I thought may be postgresql.service file is not being created by relevant program due to the presence of this file. Then I restarted the system. It's working fine since then, as you can see the output below:

[code_master5@BitBox ~]$ sudo systemctl status postgresql.service
[sudo] password for code_master5:
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor p
Active: active (running) since Sat 2017-01-28 09:31:30 IST; 7h ago
Main PID: 342 (postgres)
Tasks: 6 (limit: 4915)
CGroup: /system.slice/postgresql.service
├─342 /usr/bin/postgres -D /var/lib/postgres/data
├─358 postgres: checkpointer process
├─359 postgres: writer process
├─360 postgres: wal writer process
├─361 postgres: autovacuum launcher process
└─362 postgres: stats collector process

Jan 28 09:31:26 BitBox systemd[1]: Starting PostgreSQL database server...
Jan 28 09:31:28 BitBox postgres[340]: FATAL: the database system is starting up
Jan 28 09:31:28 BitBox postgres[340]: LOG: database system was shut down at 201
Jan 28 09:31:29 BitBox postgres[340]: FATAL: the database system is starting up
Jan 28 09:31:29 BitBox postgres[340]: LOG: MultiXact member wraparound protecti
Jan 28 09:31:29 BitBox postgres[340]: LOG: database system is ready to accept c
Jan 28 09:31:29 BitBox postgres[340]: LOG: autovacuum launcher started
Jan 28 09:31:30 BitBox systemd[1]: Started PostgreSQL database server.

I would surely like to warn all those having same problem. Please do whatever I did at your own risk. Since these are system files. Messing with these can spoil your weekend!

I am still a bit confused on this though. Explanations are welcome!

Cant't start postgresql

For run postgresql need to Switch user to postgres

Su postgres 

And

Pg_ctl start 

How to restart Postgresql

Try this as root (maybe you can use sudo or su):

/etc/init.d/postgresql restart

Without any argument the script also gives you a hint on how to restart a specific version

[Uqbar@Feynman ~] /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ...]

Similarly, in case you have it, you can also use the service tool:

[Uqbar@Feynman ~] service postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force reload|status} [version ...]

Please, pay attention to the optional [version ...] trailing argument.
That's meant to allow you, the user, to act on a specific version, in case you were running multiple ones. So you can restart version X while keeping version Y and Z untouched and running.

Finally, in case you are running systemd, then you can use systemctl like this:

[Uqbar@Feynman ~] systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-11-14 12:33:35 CET; 7min ago
...

You can replace status with stop, start or restart as well as other actions. Please refer to the documentation for full details.
In order to operate on multiple concurrent versions, the syntax is slightly different. For example to stop v12 and reload v13 you can run:

systemctl stop postgresql-12.service
systemctl reload postgresql-13.service

Thanks to @Jojo for pointing me to this very one.
Finally Keep in mind that root permissions may be needed for non-informative tasks as in the other cases seen earlier.

Set up Postgresql-93 on Centos 7

I had the same problem and solve it by changing the path

/usr/pgsql-9.3/bin/postgresql93-setup initdb

Note that the path is different

Restart PostgreSQL without postgresql-server

You can avoid troubles with serverct1 if you use standard postgres pg_ctl, eg:

pg_ctl reload

Or if needed pg_ctl reload -D $PGDATA

You dont need to restart the postgres for pg_hba changes to apply: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

The pg_hba.conf file is read on start-up and when the main server
process receives a SIGHUP signal. If you edit the file on an active
system, you will need to signal the postmaster (using pg_ctl reload or
kill -HUP) to make it re-read the file.



Related Topics



Leave a reply



Submit