How to check PostgreSQL is running or not

In this article, we will see how to check PostgreSQL is running or not on Linux and Windows.

Following commands are used to check the status of PostgreSQL is running or not on Linux Operating Systems. There are several ways to find out

1. Run these commands on terminal.

systemctl status postgresql service postgresql status /etc/init.d/postgresql status /sbin/service postgresql status

The above commands will following output:

● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since Fri 2020-10-30 17:12:25 PDT; 5h 25min ago Process: 19805 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 19805 (code=exited, status=0/SUCCESS) Oct 30 17:12:25 r2schools systemd[1]: Starting PostgreSQL RDBMS... Oct 30 17:12:25 r2schools systemd[1]: Started PostgreSQL RDBMS.

How to check PostgreSQL is running or not

2. For Debian or Debian-based (including Ubuntu) Linux distributions

sudo pg_ctlcluster 12 main status

Output:

pg_ctl: server is running (PID: 19780) /usr/lib/postgresql/12/bin/postgres "-D" "/var/lib/postgresql/12/main" "-c" "config_file=/etc/postgresql/12/main/postgresql.conf"

3. Following command works on all Linux distros.

pgrep -fa -- -D |grep postgres

Output:

19780 /usr/lib/postgresql/12/bin/postgres -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf

Where :
-f will look at the pattern in the whole commad line, not only the process name
-a will display the whole command line instead of only the process number
will allow a pattern that begins by – (like our -D).

Check the PostgreSQL server running or not on Windows.

1. open services.msc from windows+r.

2. Then go to PostgreSQL service and check the status. If it is not running, right click select start.

For the same, please watch below video: