Service guide

Run PostgreSQL as a Windows service — configure, start & recover

PostgreSQL installs as a Windows service named postgresql-x64-18. Covers start/stop commands, automatic startup, recovery on failure and log file locations.

Adjust the version number in service names if you installed PostgreSQL 16 or 17 instead of 18. Run sc query type= all | findstr postgresql to find your exact service name.

Check if the PostgreSQL service is running

cmd.exe
C:\> sc query postgresql-x64-18
STATE : 4 RUNNING
PS> Get-Service postgresql-x64-18 | Select Status,Name
Running postgresql-x64-18

Manage the service from the command line

cmd.exe — Administrator
C:\> net start postgresql-x64-18
The postgresql-x64-18 service was started successfully.
C:\> net stop postgresql-x64-18
The postgresql-x64-18 service was stopped successfully.

You can also use Services (Win+R → services.msc): find postgresql-x64-18 and right-click for Start, Stop or Restart.

Configure automatic startup on boot

cmd.exe — Administrator
# Automatic (default — starts with Windows):
C:\> sc config postgresql-x64-18 start= auto
# Manual (start on demand only):
C:\> sc config postgresql-x64-18 start= demand
Note the space after start= — required syntax for the sc command.

Restart automatically on failure

cmd.exe — Administrator
C:\> sc failure postgresql-x64-18 reset= 86400 actions= restart/5000/restart/10000/restart/30000
# Restarts after 5s, 10s, 30s on consecutive failures

Or configure visually: services.msc → double-click the service → Recovery tab → set all failure actions to Restart the Service.

Find PostgreSQL logs on Windows

cmd.exe
# Default log directory:
C:\Program Files\PostgreSQL\18\data\log\
# Open in Explorer:
C:\> explorer "C:\Program Files\PostgreSQL\18\data\log"
# Tail latest log (PowerShell):
PS> Get-Content "C:\Program Files\PostgreSQL\18\data\log\postgresql*.log" -Tail 50

Windows service questions

PostgreSQL service not starting
Check Windows Event Viewer (eventvwr.msc) under Windows Logs → Application. Also check PostgreSQL log files in the data/log folder. Common causes: port 5432 already in use, data directory permissions, or corrupted cluster. See Service not starting guide.
What account does the service run under?
By default the EDB installer uses the built-in NetworkService account. For production you may want a dedicated low-privilege service account with access only to the data directory.
How do I find the data directory path?
Run: psql -U postgres -c "SHOW data_directory;". Or check the service binary path in services.msc — it will include -D path o\data.

Service not starting?

Full troubleshooting guide for PostgreSQL startup failures on Windows.

Fix startup failures