Home » Programming » Databases » How to Check that PostgreSQL Server is Running on Linux (Ubuntu/Debian/Red Hat/Fedora)

How to Check that PostgreSQL Server is Running on Linux (Ubuntu/Debian/Red Hat/Fedora)

This tutorial will show you how to check that the PostgreSQL Server service is running on your Linux system.

To install PostgreSQL follow our tutorial here.

Checking PostgreSQL is Running on Ubuntu/Debian

To check whether the PostgreSQL server service is running successfully on your Debian or Ubuntu system, run:

sudo systemctl status postgresql

Checking the Firewall

By default PostgreSQL runs on port 5432 and is not restricted by host name.

When installing PostgreSQL on Ubuntu, usually a firewall rule will be created automatically allowing access to the database server.

You can confirm this by running the nmap command:

sudo nmap localhost

This will show the ports and service that are open on your machine – check through the list and make sure that postgresql is listed next to the port number 5432.

PORT     STATE SERVICE
80/tcp   open  http
631/tcp  open  ipp
5432/tcp open  postgresql

If it is not listed, you can open the firewall port using the ufw command:

sudo ufw allow 5432/tcp

If you have configured different a different hostname or port from the default, you may need to update your firewall rules to match.

Checking PostgreSQL is Running on Arch Linux

The process to check whether PostgreSQL is running is the same on Arch Linux, simply run:

sudo systemctl status postgresql

Checking the Firewall

Again, the nmap command is useful here for checking that the default PostgreSQL port of 5432 is open on your system:

sudo nmap localhost

Which will output something like:

PORT     STATE SERVICE
80/tcp   open  http
631/tcp  open  ipp
5432/tcp open  postgresql

If this port is not on the list, use ufw to allow the port through the firewall:

sudo ufw allow 5432/tcp

If you’ve changed from the default PostgreSQL port in your configuration, you will need to adjust your firewall rule to match.

Checking PostgreSQL is Running on Red Hat, Fedora, Centos, etc

Like Ubuntu and Arch, you can use the systemctl command to check the status of the PostgreSQL service on Red Hat based distributions:

sudo systemctl start postgresql.service

Checking the Firewall

The firewall-cmd command can be used to check that the default PostgreSQL port of 5432 is open on Red Hat based distributions:

firewall-cmd --list-all

postgressql and its port should be shown in the outputted list. If it is not, you can grant the PostgreSQL service network access through the firewall by running:

firewall-cmd --zone=public --permanent --add-service=postgresql

…or run the following to open the port:

firewall-cmd --zone=public --permanent --add-port 5432/tcp

Once changes have been made, apply them by reloading the firewall rules:

firewall-cmd --reload

Other Linux Distributions

Most modern Linux distributions (based on systemd) will use the same systemctl syntax as above to check whether a service is running.

Checking the Firewall

In the unlikely scenario where you do not have access to ufw or firewall-cmd, you can write your own iptables rules to allow traffic through your systems firewall.

To continue your PostgreSQL journey, head back to our index that lists our full PostgreSQL guide.

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment