How to start stop PostgreSQL on Ubuntu

This article covers how to start, stop and restart PostgreSQL on Ubuntu. This is PostgreSQL DBA routine task.
We are going to cover stop, start and restart using service and systemctl commands. But, not covering to kill the PostgreSQL process from Linux shell.

Stop Start and Restart PostgreSQL using service:

sudo service postgresql stop sudo service postgresql start sudo service postgresql restart

Examples for How to start stop PostgreSQL on Ubuntu:

1. To know the status of PostgreSQL Server on Ubuntu:

sudo service postgresql status

2. To stop PostgreSQL on Ubunut by using service command:

sudo service postgresql stop

To know the status of PostgreSQL Server on Ubuntu

administrator@ubuntu:~$ sudo service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: inactive (dead) since Wed 2019-07-31 02:18:48 PDT; 1s ago Process: 17332 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 17332 (code=exited, status=0/SUCCESS) Jul 31 02:17:14 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:17:14 ubuntu systemd[1]: Started PostgreSQL RDBMS. Jul 31 02:18:48 ubuntu systemd[1]: postgresql.service: Succeeded. Jul 31 02:18:48 ubuntu systemd[1]: Stopped PostgreSQL RDBMS.

3. To start PostgreSQL on Ubunut by using service command:

sudo service postgresql start

administrator@ubuntu:~$ sudo service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2019-07-31 02:19:03 PDT; 1s ago Process: 17572 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 17572 (code=exited, status=0/SUCCESS) Jul 31 02:19:03 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:19:03 ubuntu systemd[1]: Started PostgreSQL RDBMS.

4. To restart PostgreSQL on Ubunut by using service command:

sudo service postgresql restart

administrator@ubuntu:~$ sudo service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2019-07-31 02:19:14 PDT; 3s ago Process: 17641 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 17641 (code=exited, status=0/SUCCESS) Jul 31 02:19:14 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:19:14 ubuntu systemd[1]: Started PostgreSQL RDBMS.

Method2: To start stop PostgreSQL on Ubuntu using systemctl:
Following commands are used to start stop PostgreSQL on Ubuntu using systemctl:

sudo systemctl stop postgresql sudo systemctl start postgresql sudo systemctl restart postgresql sudo systemctl status postgresql

1. Start the PostgreSQL Stop on Ubunut:

sudo systemctl stop postgresql

root@ubuntu:/var/lib/postgresql# systemctl status postgresql ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: inactive (dead) since Wed 2019-07-31 02:00:46 PDT; 2s ago Process: 15862 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 15862 (code=exited, status=0/SUCCESS) Jul 31 02:00:27 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:00:27 ubuntu systemd[1]: Started PostgreSQL RDBMS. Jul 31 02:00:46 ubuntu systemd[1]: postgresql.service: Succeeded. Jul 31 02:00:46 ubuntu systemd[1]: Stopped PostgreSQL RDBMS.

2. Start the PostgreSQL Server on Ubunut:

sudo systemctl start postgresql

root@ubuntu:/var/lib/postgresql# systemctl status postgresql ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2019-07-31 02:00:27 PDT; 11s ago Process: 15862 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 15862 (code=exited, status=0/SUCCESS) Jul 31 02:00:27 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:00:27 ubuntu systemd[1]: Started PostgreSQL RDBMS.

3. Start the PostgreSQL Server on Ubunut:

sudo systemctl restart postgresql

administrator@ubuntu:~$ sudo service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2019-07-31 02:19:14 PDT; 3s ago Process: 17641 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 17641 (code=exited, status=0/SUCCESS) Jul 31 02:19:14 ubuntu systemd[1]: Starting PostgreSQL RDBMS... Jul 31 02:19:14 ubuntu systemd[1]: Started PostgreSQL RDBMS.

For video tutorial for same “How to start stop PostgreSQL on Ubuntu”, watch below video.

Leave a Reply

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