Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 postmaster.pid file on disk which prevents the service from restarting.

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

share|improve this question

1 Answer 1

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
1  
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

 
discard

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.