How to Check PostgreSQL Service Status in Linux(Ubuntu)

PostgreSQL is one of the frequently used relational databases that assist us in storing data securely and efficiently. It offers numerous features, such as security, faster query execution, open-source development, etc. However, you need to install Postgres on your machine to earn these features. The Postgres Service status needs to be checked after installation in order to use the PostgreSQL database smoothly.

This write-up will explain how to check the status of the Postgres service using practical demonstration. The outcomes of this post are enlisted below:

- How to Check if Postgres is Installed or Not?
- How to Check the Status of Postgres Service?
- How to Check if the Postgres Service is Active?
- How to Check if the Postgres Service is Enabled?
- How to Check if PostgreSQL is Ready to Accept/Recieve User Connections?

How to Check if Postgres is Installed or Not?

Firstly, launch the terminal and connect to the “postgres” user via the below-given “sudo” command:

sudo -i -u postgres
img

Now run the “psql” command from the terminal to access the “postgres”:

psql
img

The output proves that the Postgres database is installed on your Ubuntu system. If Postgres is not installed on your system then first, you must install it on your system.

How to Check the Status of Postgres Service?

Open the terminal and utilize the below-provided command to check the status of the Postgres service:

sudo systemctl status postgresql
img

From the output snippet, you can observe that the “Postgres service” is currently enabled and active.

Alternatively, you can use the “systemctl” command with different options, like “is-active” or “is-enabled” to check the status of the Postgres service with respect to a specific parameter.

How to Check if the Postgres Service is Active?

Use the “systemctl” command with the “is-active” option to check if Postgres is operating or not:

sudo systemctl is-active postgresql
img

The output shows that “Postgres” is active.

How to Check if the Postgres Service is Enabled?

Use the “sudo systmctl” command with the “is-enabled” option to check if the Postgres service is enabled or not:

sudo systemctl is-enabled postgresql
img

The output proved that Postgres is currently enabled.

How to Check if PostgreSQL is Ready to Accept/Recieve User Connections?

Use the "sudo pg_isready" command to check whether Postgres is ready for client connections or not:

sudo pg_isready
img

The output clarifies that Postgres is accepting the users’ connections at the default port, i.e., 5432.

That’s all from this guide.

Conclusion

Use the “sudo systemctl status postgresql” command to check the PostgreSQL service status in Linux. Users can also use the “sudo systemctl is-active postgresql” and “sudo systemctl is-enabled postgresql” commands to check if the Postgres service is active and enabled. Moreover, users can execute the "sudo pg_isready" command to check whether Postgres is ready for client connections or not.

This post presented a comprehensive guide on how to check the status of Postgres service on the Linux (Ubuntu) operating system.