PostgreSQL stale ‘postmaster.pid’ error

Danielle McCarthy
2 min readApr 18, 2019

--

These are instructions to fix a common PostgreSQL database error. This error most commonly will look something like: $ FATAL: lock file “postmaster.pid” already exists

Sometimes when your computer dies or crashes you’ll come across an error with your Postgres database that mentions the postmaster.pid file. This happens when the Postgres process dies without cleaning up its pid file.

The solution is to remove the postmaster.pid file. This is not a solution for a production system and it may not work for you depending on how you’ve set up PostgreSQL on your machine.

Before going through these steps make sure that there are no Postgres processes running so you do not permanently corrupt your database. To make sure, open your Activity monitor and check that there are no processes named ‘postgres’ or ‘postmaster’ running.

  1. Open your terminal and make sure you’re in the home directory.
  2. Navigate to the Postgres directory. cd Library/Application\ Support/Postgres
  3. Type ls to view the files in your Postgres directory. Most likely there will be a directory called var-11. Navigate to this folder cd var-11
  4. The last step is to remove the postmaster.pid file. If you’d like to see all the files in the var-11 directory you can type ls -a into your terminal, otherwise, once you’re in the var-11 directory go ahead and type rm postmaster.pid This will remove the stale file and you will now be able to start your PostgreSQL server.

If PostgreSQL is set up differently on your computer feel free to comment with the correct file path to help others!

New and improved: If your postmaster.pid file is not located in the same directory as shown in this article run the command find ~ -name postmaster.pid\* and continue to step 4. Thank you for the tip Mike Tsubasa.

--

--

Danielle McCarthy

Software Engineer, Virginian turned New Yorker, not a writer. Contact me @whatdanielle on Twitter & IG.