How to Restart PostgreSQL Server on Linux

PostgreSQL is a widely used relational database that is compatible with various operating systems, such as Windows, Linux, and MacOS. Installing PostgreSQL on Linux allows users to perform various database functions efficiently, such as storing, managing, and retrieving large amounts of data. However, sometimes you may need to restart the Postgres server because of various reasons, such as when the server is inactive/dead, to enforce updates, when a system crashes, a lag occurs, etc.

This post is going to present a step-by-step guide on restarting the PostgreSQL server on the Linux operating system.

How to Restart Postgres Server on Linux(Ubuntu)?

The Postgres Server can be restarted using various methods. In this write-up the below-given methods will be demonstrated to restart the Postgres server on Linux:

- Method 1: Using the “/etc/init.d/postgresql” Directory
- Method 2: Using the “systemctl” Command

How to Restart Postgres on Linux Using the “/etc/init.d/postgresql” Directory?

Follow the given instructions to restart a Postgres server on Linux without any obstacles:

Step 1: Check the Postgres Status

Open the terminal and run the following “sudo” command to see the current status of the Postgres server:

/etc/init.d/postgresql status
img

The output shows that the Postgres server is currently inactive.

Step 2: Restart the Postgres Server

Use the below command to restart the Postgres server via the “/etc/init.d/postgresql” directory:

/etc/init.d/postgresql restart
img

The output shows that the stated command was executed successfully.

Step 3: Verify the Postgres Status

Use the “/etc/init.d/postgresql” directory with the “status” option to verify the Postgres status:

/etc/init.d/postgresql status
img

The output shows that the Postgres Server has been activated/restarted successfully.

How to Restart Postgres Server on Linux Using the “systemctl” Command?

Let’s head towards the below-listed steps to learn how to restart Postgres Server on Linux:

Step 1: Check the Status

Type the following “systemctl” command to see the current status of the Postgres server:

sudo systemctl status postgresql
img

The output shows that the Postgres server is currently not functioning.

Step 2: Restart the Postgres Server

Type the following sudo command to restart the Postgres server:

sudo systemctl restart postgresql
img

The output shows that the input command was executed successfully.

Step 3: Confirm the Status

To confirm that if Postgres is restarted or not, use the "systemctl" command with the "status" option:

sudo systemctl status postgresql
img

The output proves that the Postgres server has been restarted successfully.

Conclusion

The Postgres server can be restarted using the “/etc/init.d/postgresql restart” or “sudo systemctl restart postgresql” commands. The status of the Postgres server can be confirmed by executing these commands with the “status” option. In Postgres, the need to restart the Postgres server arises because of various reasons, such as to activate the dead server, enforce updates, tackle system crashes, overcome lags, etc. This article has explained the step-by-step guide on restarting the PostgreSQL server on Linux.