PostgreSQL is an advanced, freely available, and highly stable relational database management system that offers numerous features, such as accuracy, integrity, resilience, etc. The Postgres database is widely used for storing data of web apps, mobile apps, analytical apps, etc. However, to attain any Postgres features, you must know how to start, stop, or restart a Postgres Server.
To tackle such scenarios, Postgres offers different methods, such as the “pg_ctl” utility, “services” manager, etc. This post presents a practical guide on how to start, stop, or restart the PostgreSQL server on the Windows Operating System.
How Do I Start the Postgres Server?
There are various ways to start the Postgres server on Windows, such as using the “net start” command, “pg_ctl” utility, or “services” manager.
Method 1: Starting Postgres Server Using “net start”
Launch the Windows CMD as an administrator and execute the “net start” command to start the Postgres Server:
net start postgresql-x64-15
Method 2: Starting Postgres Server Using “pg_ctl”
Firstly, you need to find the directory’s path where Postgres is located. If you didn’t change the default path while installing Postgres, then it must be located in the “Program Files” directory inside the “C” drive.
The complete path will look something like this: “C:\Program Files\PostgreSQL\15\data”:
Once you find the complete path, open the CMD and execute the following command to “start the Postgres Server”:
pg_ctl -D "C:\Program Files\PostgreSQL\15\data" start
Note: Windows Path for Postgres tools must be set to get the error-free output. Else you will encounter a “not recognized as an internal/external command” error.
Method 3: Starting Postgres Server Using Services Manager
Press the “win” key + “R” to launch the “Run” window. Type the “services.msc” and hit the “OK” button to open the Services Manager:
In the “Services Manager”, search for “Postgresql-x64-15”, select the service, and hit the “Start/play” button to start a Postgres server via the “services” manager:
Once you press the “start” button the service’s status will be changed to “running”:
How to Stop the Postgres Server on Windows?
A Postgres server can be stopped using the “net stop” command, the “pg_ctl” utility, or the “services” manager.
Method 1: Stopping the Postgres Server Using “net stop”
Execute the below-mentioned command from the Command prompt to stop the Postgres Server:
net stop postgresql-x64-15
Method 2: Stopping the PostgreSQL Server via the “pg_ctl”
Users may use the “pg_ctl” utility to stop the Postgres server:
pg_ctl -D "C:\Program Files\PostgreSQL\15\data" stop
Method 3: Stopping the Postgres Server Using the Services Manager
Open the “Services Manager”, search for “Postgresql-x64-15”, select the service, and hit the “Stop” button to stop a Postgres server via the “services” manager:
Clicking on the “Stop” button will stop the Postgres Server.
Note: Similarly, to pause a Postgres Server on Windows, you can select the “pause” button from the Services manager or execute the “net pause postgresql-x64-15” command from the command prompt.
How Do I Restart the Postgres Server on Windows?
You can restart the Postgres server on the windows operating system using the “Services” Manager and “pg_ctl” utility.
Method 1: Restarting the Postgres Server via the “pg_ctl”
Run the below-given command from the CMD to restart the Postgres Server:
pg_ctl -D "C:\Program Files\PostgreSQL\15\data" restart
Method 2: Restarting the Postgres Server Using the Services Manager
Launch the “Services Manager”, locate the “Postgresql-x64-15”, select the desired service, and hit the “restart” button to restart a Postgres server via the “services” manager:
Clicking on the Restart button will restart the Postgres Server.
Conclusion
There are various ways to start, stop, or restart the Postgres server on Windows, such as using the “net start” command, “pg_ctl” utility, or “services” manager. To get the error-free output, Windows Path for Postgres tools must be set. Else you will encounter a “not recognized as an internal/external command” error. This post presented a practical guide on how to start, stop, or restart the PostgreSQL server on the windows operating system.