Service management is a prevalent task for system administrators and power users. For example, one of the common tasks of a database or system administrator is ensuring that the database servers are running smoothly.
This tutorial explores the various methods and techniques that you can use to restart the PostgreSQL server on different systems.
NOTE: It is good to keep in mind that the steps and techniques that are discussed in this tutorial may vary depending on the target system, installed version, and installation method.
Restarting PostgreSQL on Linux
On Linux, there are several methods that you can use to restart the PostgreSQL server. However, these methods may require sudo permissions.
Using the Systemd
To restart PostgreSQL using the systemd, open the terminal and run the following command as follows:
Using the Service Command
You can also use the service command to restart PostgreSQL on Linux. The command is as follows:
Manual Restart
You can also perform a manual restart using the provided PostgreSQL binaries. The commands are as follows:
Open the terminal and locate the data directory for your PostgreSQL installation. The common locations are in /var/lib/postgresql/<version>/data or /var/lib/postgresql/<version>data.
Run the following command to stop the PostgreSQL server:
Once the server is stopped, run the following command to start it back again.
This should bring back up the PostgreSQL server.
Restart PostgreSQL on MacOS
Similarly, the methods vary depending on the installation method in PostgreSQL.
Using Homebrew
If you installed PostgreSQL on macOS using Homebrew, you can use the Homebrew service manager as shown in the following command:
Restart PostgreSQL on Windows
On Windows, you can use two main methods to restart the PostgreSQL server.
Using the Command Prompt
Start by launching the command prompt as an administrator.
Next, navigate to the PostgreSQL bin directory. If you used the default install directory, head over to C:\Program Files\PostgreSQL\<version>\bin.
Finally, run the following command to restart PostgreSQL:
This should restart the PostgreSQL server using the pg_ctl utility. Remember to replace the version with your installed PostgreSQL version.
Using the Windows Services
You can also use the Windows Service administration tool. To launch the Services Manager, press the Windows Key + R and type “services.msc”.
Locate the PostgreSQL service from the services window.
Right-click on the service and select “Restart”.
Conclusion
We explored the various methods and techniques that you can use to restart the PostgreSQL server on Linux, Windows, and macOS.