How to Restart PostgreSQL (Linux, Windows, Mac)

In this PostgreSQL tutorial, we will learn how to restart PostgreSQL services or servers in various platforms like Windows, Mac, and Linux. Also, we will cover these topics:

  • How to Restart Postgres Server
  • How to Restart PostgreSQL Service in Linux
  • How to Restart Postgres Sevice in Mac
  • How to Restart PostgreSQL Service
  • How to Restart PostgreSQL in Windows
  • How to Restart Postgres in Ubuntu
  • How to Restart Postgres Service in Ubuntu
  • How to Restart Postgres Server in Ubuntu
  • How to Restart Postgres Service in Centos

How to Restart Postgres Service

In this section, we will see why do we need to restart the PostgreSQL services on various platforms like Windows, Mac, and Linux.

  • Software is a mysterious thing that may break or stop working while it was running fine a few minutes back. There could be ‘n’ number of reasons why the bug appeared in the program.
  • Whenever this happens the first thing we do is restart our system & most of the time it works.
  • But when a developer sees an error, he tries to understand it. So instead of rebooting the system, he restarts the services of that program.
  • If the problem is not solved after restarting services that means some other software or driver or any malware is creating a problem.
  • To restart PostgreSQL services, we use systemctl in Linux, services in Mac and windows.
  • Moving ahead we will see all of these in detail.

Read: How to create a table in PostgreSQL [Terminal + pgAdmin]

How to Restart Postgres Service in Linux

In this section, we will learn how to Restart Postgres Service in Red Hat Linux. Red Hat is the Linux RPM package.

  • Linux Debian package users can see How to Restart Postgres in Ubuntu section below.
  • Linux provides a power command systemctl using which we can start, stop, restart and view the status of any service on the Linux machine.
  • In the below command we have used status to know the current state of the PostgreSQL service.
sudo systemctl status postgresql-13.service
  • In the below image, the output of the above command shows the status of the PostgreSQL service.
  • The service is in an active (running) state. Also, please make a note of the time so that you can compare it with an upcoming image.
how to restart postgres
  • Type the below command to restart the PostgreSQL services. Here restart is the keyword behind the operation.
sudo systemctl restart postgresql-13.service
  • In the below image, the PostgreSQL service is restarted and now the time running says 13s ago which means machine is just now started.
restart postgres service in rpm package of Linux
how to restart postgres

How to Restart Postgres Sevice in Mac

In this tutorial, we will learn how to restart PostgreSQL service in Mac operating system. We will be using brew to restart the PostgreSQL services.

  • Open terminal and type the following command.
sudo brew services restart postgresql
  • The PostgreSQL services will be restarted in Mac operating system.

How to Restart Postgres in Windows

In this section, we will learn how to restart Postgres in Windows. This tutorial will work on Windows 10, Windows 8, 8.1, Windows 7.

  • Press Windows key + R, ‘RUN’ box will appear.
  • Type services.msc in the Run box and hit enter.
  • Services window will open, search for postgresql-13. Here 13 is the version of PostgreSQL installed in the window machine.
  • Right-click on the postgresql-13 and click on the restart option.
  • The services will restart now.
  • This is how we can restart PostgreSQL services in windows machines.

Read: PostgreSQL installation on Linux step by step

How to Restart Postgres in Ubuntu

In this section, we will learn how to restart PostgreSQL in Ubuntu operating system. Ubuntu is a Linux Debian package.

  • If you are using Red hat, Centos or Fedora then follow the instructions in How to Restart Postgres Service in Linux section above.
  • Linux provides a power command systemctl using which we can start, stop, restart and view the status of any service on the Linux machine.
  • In the below command we have used status to know the current state of the PostgreSQL service.
sudo systemctl status postgresql.service
  • In the below image, the output of the above command shows the status of the PostgreSQL service.
  • The service is in an active (running) state. Also, please make a note of the time so that you can compare it with an upcoming image.
Restart Postgres in Ubuntu
Restart Postgres in Ubuntu
  • Type the below command to restart the PostgreSQL services. Here, restart is the keyword behind the operation. It stops the service and then start it again.
sudo systemctl restart postgresql.service
  • In the below image, we have restarted the PostgreSQL service and now the total running time of the service has been changed from 23m to 10s. This means the service has been started just now.
How to Restart Postgres in Ubuntu
Restart Postgres in Ubuntu

How to Restart Postgres Server

In this section, we will learn how to restart Postgres Server. The server could be local or cloud-based.

  • Ubuntu server, Red Hat server, etc are examples of local servers that we can be created to manage work on a small scale.
  • AWS, Azure, Digital Ocean, etc comes under cloud-based servers and they are dedicated to large work.
  • In this section, we have used the Red Hat server, which is a local server created on our own network. Please note that this machine is destroyed after publishing this tutorial.
  • Linux provides a powerful command systemctl using which we can start, stop, restart and view the current status of the services running on the machine.
  • In the below command we have used status to know the current state of the PostgreSQL service.
sudo systemctl status postgresql-13.service
  • The service is in an active (running) state. Also, please make a note of the time so that you can compare it with an upcoming image.
how to restart postgresql mac
how to restart postgresql mac
  • Type the below command to restart the PostgreSQL services. Here, restart is the keyword behind the operation. It stops the service and then start it again.
sudo systemctl restart postgresql-13.service
  • In the below image, we have restarted the PostgreSQL service and now the total running time of the service has been changed from 17m to 9s. This means the service has been started just now.
How to Restart Postgres Server
How to Restart Postgres Server

How to Restart Postgres Service in Ubuntu

In this section, we will learn how to restart PostgreSQL in Ubuntu operating system. Ubuntu is a Linux Debian package.

  • If you are using Red hat, Centos or Fedora then follow the instructions in How to Restart Postgres Service in Linux section above.
  • Linux provides a power command systemctl using which we can start, stop, restart and view the status of any service on the Linux machine.
  • In the below command we have used status to know the current state of the PostgreSQL service.
sudo systemctl status postgresql.service
  • In the below image, the output of the above command shows the status of the PostgreSQL service.
  • The service is in an active (running) state. Also, please make a note of the time so that you can compare it with an upcoming image.
Restart Postgres Service in Ubuntu
Restart Postgres Service in Ubuntu
  • Type the below command to restart the PostgreSQL services. Here, restart is the keyword behind the operation. It stops the service and then starts it again.
sudo systemctl restart postgresql.service
  • In the below image, we have restarted the PostgreSQL service and now the total running time of the service has been changed from 23m to 10s. This means the service has been started just now.
restart postgres service in ubuntu
Restart Postgres Service in Ubuntu

How to Restart Postgres Server in Ubuntu

In this section, we will learn how to restart PostgreSQL server in Ubuntu. There are two types of services available under Ubuntu postgresql@13-main.service and postgresql.service.

  • If postgresql.service controls all the activities related to postgreSQL. If this service is stopped then postgresql@13-main.service also stops.
  • postgresql@13-main.service is the PostgreSQL server if this service is stopped then the user won’t be able to access the PostgreSQL.
  • In this section, we will learn how to restart postgresql@13-main.service.
  • Linux provides a powerful command systemctl using which we can start, stop, restart or view the status of the services running on the machine.
  • Below is the command to restart the Postgres server in ubuntu.
sudo systemctl retart postgresql@13-main.service
  • In the below output, we have stopped the main services and then we have tried to access the PostgreSQL.
  • ‘could not connect to server’, an error appeared on the screen.
  • To connect back we have run the restart command now we are able to access the Postgres.
restart Postgres server in ubuntu

How to Restart Postgres Service in Centos

In this section, we will learn how to Restart Postgres Service in Centos Linux. Centos is the Linux RPM package.

  • Linux Debian package users can see How to Restart Postgres in Ubuntu section above.
  • Linux provides a power command systemctl using which we can start, stop, restart and view the status of any service on the Linux machine.
  • In the below command we have used status to know the current state of the PostgreSQL service.
sudo systemctl status postgresql-13.service
  • In the below image, the output of the above command shows the status of the PostgreSQL service.
  • The service is in an active (running) state. Also, please make a note of the time so that you can compare it with an upcoming image.
How to Restart Postgres Service in Centos
How to Restart Postgres Service in Centos
  • Type the below command to restart the PostgreSQL services. Here restart is the keyword behind the operation.
sudo systemctl restart postgresql-13.service
  • In the below image, the PostgreSQL service is restarted and now the time running says 13s ago which means machine is just now started.
restart postgres service in rpm package of Linux
restart postgres centos

You may like the following articles:

In this tutorial, we have learned how to how to restart PostgreSQL service in Linux. Also, we have covered these topics.

  • How to Restart Postgres Service in Linux
  • How to Restart Postgres in Mac
  • How to Restart Postgres Sevice in Mac
  • How to Restart Postgres in Windows
  • How to Restart Postgres in Ubuntu
  • How to Restart Postgres Server
  • How to Restart Postgres Service in Ubuntu
  • How to Restart Postgres Server in Ubuntu
  • How to Restart Postgres Service in Centos