How to Restart PostgreSQL in Ubuntu?

On Linux, PostgreSQL is an open-source free database system that lies in the relational DBMS category. It stores and manages the data in a way of building user-defined data types, custom functions, implementation of other programming languages, and many others. The PostgreSQL server needs to be restarted after updating to its newer version for making it up to date, or in case its services are not working properly.

This post provides deep insight into how to restart PostgreSQL in Ubuntu:

  • Using the “systemctl” Command 
  • Using the “service” Command 

Method 1: Using the “systemctl” Command 

The “systemctl” is the Debian-based command-line tool that can access and manage the “systemd” initialization system and service manager. It offers a wide range of options for interacting with the system services like “start”, “enable”, “disable”, “start”, and “stop”.

Restart PostgreSQL Service

Specify the “restart” option with the “systemctl” command and also the system administrator privileges in the form of “sudo” to restart PostgreSQL:

$ sudo systemctl restart postgresql

The command has successfully restarted the PostgreSQL.

Check PostgreSQL Status

When the “PostgreSQL” server is restarted then check its current status using the “status” option with the “systemctl” command:

$ sudo systemctl status postgresql

The output shows that PostgreSQL is in an “active (exited)” state.

Method 2: Using the “service” Command 

Another command line tool to restart PostgreSQL is the “service” command. It is mainly used to run a SystemV init script which is in the /etc/init.d directory. In addition, it also assists the users to perform the start, restart, stop, and reload operations on the system services like the systemctl command.

Restart PostgreSQL Service

Use the “restart” keyword at the end of the “service” command to restart “PostgreSQL” having the support of the “sudo” utility as well:

$ sudo service postgresql restart

The “service” utility has also restarted the PostgreSQL quickly.

Conclusion

Ubuntu provides the “systemctl” and “service” command line managers to restart the “PostgreSQL” server quickly. These utilities require the system root user rights i.e., “sudo” in case of a normal logged-in user. Apart from Ubuntu, these utilities are also useful for other Linux distributions.

This post has covered all possible workable methods to restart PostgreSQL in Ubuntu.