Skip to content

Instantly share code, notes, and snippets.

@pingzh
Last active May 24, 2016 01:49
Show Gist options
  • Save pingzh/5a72099c8161511c706a to your computer and use it in GitHub Desktop.
Save pingzh/5a72099c8161511c706a to your computer and use it in GitHub Desktop.

Public service announcement: never delete postmaster.pid. Really. Great way to get data corruption.

You already had PostgreSQL installed, and you deleted the data dir without stopping the running server. So you now have some orphan PostgreSQL server processes that are managing data files that've been deleted, so they're no longer accessible in the file system and will be fully deleted when the last open file handle to them is closed. You can't use pg_ctl to shut the server down like normal because you've deleted the cluster datadir, so you must simply kill the processes. Kill the postmaster (do not use kill -9, just an ordinary kill will do) and the rest will shut down too.

You will then be able to start a new server in the datadir against the freshly initdb'd data.

It is highly likely that you will experience conflicts down the track unless you uninstall the other older version of PostgreSQL.

In a nutshell:

cat /usr/local/var/postgres/postmaster.pid

Note down the number on the first line, which is the pid of the postmaster. Kill the postmaster process with the following command, replacing 'PID' with the number you have noted down. Again, do not use kill -9 or kill -KILL, just use a plain kill, i.e. a SIGTERM:

kill PID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment