Running postgres as a service on windows starts and stops immediately
Sebastian Wright
Since I restarted windows to install updates, Postgres stopped starting as a service. I thought it may be a permissions so I gave everyone the ability to to modify the postgres install folder. I then tried to run the database using the start and it works. But when I try and start the service I get the following message: service on local computer started and stopped.
I then tried to re-install Postgres but it got to the end and it was not able to start.
Any help would be great.
65 Answers
I had the same issue on v9.4
I found that deleting c:\Program Files(x86)\PostgreSQL\9.4\data\postmaster.pid and \postmaster.opts then restarting the service resolves the issue.
The solution to the problem was to completely uninstall Postgres and re-install it. I made sure I deleted all traces of it from the disk before re-installing. That seemed to be the only way to get it working.
I faced exactly the same issue and a good old fashioned system restart worked for me. So, before trying any of the above solutions, I would recommend restarting your system once.
1Deleting .pid file seems like the way to go.
While I found many people recommending it without actually understanding why, this troubleshooting doc from Postgre's doc cleared it up.
Quoting for longevity of the answer:
The data directory contains an old postmaster.pid file / The datadirectory contains an unreadable postmaster.pid file
PostgreSQL puts a file named postmaster.pid in the data directory to store the process id of the PostgreSQL server process. If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL. You can fix this issue by deleting the postmaster.pid file. However, you must make sure that PostgreSQL is really not running. Open Activity Monitor and make sure that there are no processes named ‘postgres’ or ‘postmaster’.
If you delete the postmaster.pid file while PostgreSQL is running, bad things will happen.
Never do anything drastic like uninstalling and reinstalling without checking the error logs:
(Windows) C:\Program Files\PostgreSQL<version>\data\log
The problem could be something very simple like (in my case) an ip address in pg_hba.conf missing its mask - blindly uninstalling probably wouldn't work in cases like that.