Linux PostgreSQL Restart Command

PostgreSQL is an open source object-relational multi-platform database management system and one of the most popular alternatives to MYSQL. It is available on Windows, MacOS, Linux and Unix based systems. Today we will show you how to restart postgresql on Linux, you will also learn how to stop, start and get the full pgsql status from the Linux terminal.

linux restart postgresql command

PostgreSQL service management commands

This guide applies to plain CentOS 6.x and CentOS 7.x, same as RHEL 6.x and RHEL 7.x systems, although if you installed from scratch it may work on many Linux distributions.

PostgreSQL Status Service

If you need to verify postgresql server status, you can run this commands:

CentOS 6.x rpm based installation

service postgresql status

CentOS 7.x rpm based installation

On CentOS 7 things changed, and while you can still use the old “service” command, the idea is to switch to systemd, this is the command to get the full status of postgresql from CentOS 7.x

/bin/systemctl status postgresql

Compiling & installing from source code

su - postgres
/usr/local/pgsql/bin/pg_ctl status -D /usr/local/pgsql/data

PostgreSQL Stop Service

Installation from source code

su - postgres
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data

CentOS 6.x RPM based installation syntax

service postgresql stop

CentOS 7.x RPM based installation syntax

/bin/systemctl stop postgresql

PostgreSQL Start Service

If you compiled pgsql from source code, try this:

su - postgres
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &

CentOS 6.x rpm based installation sintax

service postgresql start

CentOS 7.x rpm based installation sintax

/bin/systemctl stop postgresql

PostgreSQL Restart Command

If the pgsql version you are running was compiled from source code (scratch), then you will have to stop and start the service manually, for example:

su - postgres
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &

CentOS 6.x Pgsql Restart for RPM installations

service postgresql restart

CentOS 7.x PostgreSQL Restart for .rpm installations

/bin/systemctl restart postgresql

PostgreSQL Configuration file

If you ever need to change something on the configuration, you can edit this file. The location depends on how you installed pgsql into your system, it is usually located at:

nano -w /usr/local/pgsql/data/postgresql.conf


nano -w /var/lib/pgsql/data/pg_hba.conf

Expected more? No, that’s all for today, now you know the PostgreSQL restart command, but also how to stop, start, get the full pgsql status of your database server.

Further reading:


About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *