PostgreSQL stale ‘postmaster.pid’ error
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.
- Open your terminal and make sure you’re in the home directory.
- Navigate to the Postgres directory.
cd Library/Application\ Support/Postgres
- Type
ls
to view the files in your Postgres directory. Most likely there will be a directory calledvar-11.
Navigate to this foldercd var-11
- 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 typels -a
into your terminal, otherwise, once you’re in thevar-11
directory go ahead and typerm 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.