I have been seeing this error lately that is causing the server to crash all of a sudden. I have seen elsewhere that the solution is to delete the postmaster.pid and postmaster.opts files and restart the server, but no one has explained why this event happens, and how to stop it from happening again.

  • 1
    What operating system and version are you on? Do you ever manually kill postgres processes or have a cron job that does it? Never delete postmaster.pid, you risk severe database corruption. – Craig Ringer Jan 17 '15 at 4:28
  • 1
    It's a Docker container running on Ubuntu Trusty. The database shares a volume with the host to store its data. What you said about killing postgres processes reminded me that I have killed the container a couple of times. What would be the right thing to do? – picardo Jan 18 '15 at 4:51

It's vital that if you forcibly terminate PostgreSQL then all postgres processes must be killed. If you don't terminate them all then the shared memory block may still be held and the database files may still be open and being written to. In this case starting PostgreSQL again may cause massive database corruption, which is why PostgreSQL tries to stop you doing this. Overriding those safety measures may cause data loss.

You should preferably cleanly stop PostgreSQL with pg_ctl as part of the container shutdown process.

In any case, it's very important that stopping the container terminates all postgres processes.

You should not delete postmaster.pid, it's protecting you from data corruption by allowing PostgreSQL to notice that the shared memory segment is still in use. Unless Docker somehow gets in the way of this process.

  • Thank you! I think restarting the container after killing it was not bringing up the server, which is why I removed the pid file. But from now on I will always shutdown the containers gracefully. – picardo Jan 18 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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