Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have experienced an annoying problem with Postgresql 9.1.1 x64 running as a Windows service on Windows 2008 R2.

The Postgres service crashed for an unknown reason and it left a file on disk which prevents the service from restarting.

Is there a way to configure the creation of this file?

share|improve this question
up vote 3 down vote accepted

This is a safety feature - on Windows the Postgres server uses its PID file as a lock to prevent you from starting more than one postmaster pointing at the same data directory (a quick and easy way to destroy your database).
You should not be looking for ways to bypass this functionality.

If Postgres has actually exited you can remove the PID file and restart it.
You should also be examining your Postgres error logs to find out why the server crashed, and addressing that issue.

share|improve this answer
Yeah. Specifically, the postmaster has no way to be sure that all the backends of the crashed database server have exited. It doesn't know what their process IDs were and they could've been re-used anyway. It relies on the administrator to make sure any postgres.exe backends from that cluster that survived the crash are killed before it's restarted. It'd be nice to make this automatic, but it's also surprisingly difficult. – Craig Ringer Aug 5 '12 at 3:27
@CraigRinger Only because Windows lacks a SysV shared memory work-alike :-) – voretaq7 Aug 5 '12 at 4:03
@voretaq7 : Is this tied to the process per connection model of PostgreSQL on Windows ? I'm trying to understand how we could end up with several postmaster pointing to the same data directory on Windows (Especially while running as a Windows Service). – omatrot Aug 6 '12 at 7:42
@CraigRinger : I do not know about SysV, but Windows has Memory Mapped Files to deal with inter process communication. – omatrot Aug 6 '12 at 7:44
@voretaq7 While I think the Unix worse is better approach is better and you should just write a lock file on Window, you can use a mutex. I've never done it in unmanaged code, but I've used a pattern similar to this in C# – Justin Dearing Aug 6 '12 at 14:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.