FATAL ERROR lock file "postmaster.pid" already exists

PostgresqlPostgis

Postgresql Problem Overview


I have recently installed PostGIS on my Mac (El Capitan 10.11.4, Postgres is version 9.5.1) using Homebrew, and I am following these instructions - http://morphocode.com/how-to-install-postgis-on-mac-os-x/

When I try to start Postgres using

pg_ctl -D /usr/local/var/postgres start 

I get the following error:

$ FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 280) running in data directory "/usr/local/var/postgres"?

So I spent a few hours researching how to address this, but to no avail.

Notably, I tried to kill the PID as recommended in an answer on Superuser - https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists- (in the case above, I ran kill 208), but as soon as I tried to start Postgres again, I got the same error, albeit with a different PID number. I saw a few people recommended deleting the postmaster.pid file, but I feel like maybe I should save that as a last resort...

Admittedly part of the reason I'm not sure how to fix this is that I'm not really clear on what the postmaster even is - I'm just starting to learn about all of this.

Hopping into a Postgres database via the psql db_name command works just fine, for what it's worth.

Postgresql Solutions


Solution 1 - Postgresql

Posting this in case it helps someone else:

I was having this same problem as the OP after a hard reboot when my laptop crashed. What helped me was running the following command to see what PID was associated with postmaster.pid:

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

The first number that appears will be the PID. Looking in Activity Monitor, I was able to see that Postgres was running, but without a PID number that matched the one shown.

Instead of the steps outlined in the answer referenced on Superuser, I restarted my laptop properly and then opened up Terminal and ran

brew services restart postgresql

This worked without having to remove postmaster.pid, which I saw a few other posts recommend. Sometimes it's the simple solutions that work.

Solution 2 - Postgresql

It often happens to me in OSx, when my system shutdown unexpectedly.

You can just remove the file postmaster.pid.

cd Library/Application Support/Postgres/var-{postgres-version}

and remove the postmaster.pid file

in case you use brew then your path should be something like:

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

restart the Postgres by using this command

pg_ctl -D /usr/local/var/postgres restart

Solution 3 - Postgresql

I add here what worked for me, after a long time of searching:

  1. Delete the postmaster.pid file:

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

  2. Restart your postgres:

    brew services restart postgresql

Hope this helps someone ...

Solution 4 - Postgresql

Since you can connect to the database, you don't need to start the server again - it's already running.


[pg_ctl][1] is used to control the PostgreSQL server. Since your server is already started, your command:

pg_ctl -D /usr/local/var/postgres start

Returns an error, saying that there is a lock on postmaster.pid - which is true since there is already a server running under that PID.


There are two ways:

  1. The most basic way - skip that step, your server is already running!
  2. Executing a needless operation - stopping the server, and then starting it again.

You could stop your server doing :

pg_ctl -D /usr/local/var/postgres stop

So that you won't have the lock on postmaster anymore and you could use your command to start it again. [1]: https://www.postgresql.org/docs/current/static/app-pg-ctl.html

Solution 5 - Postgresql

Postmaster is the main PostgreSQL process. You're trying to start PostgreSQL that's already running (and you're saying yourself you can connect to it). Just skip that step of your process.

Solution 6 - Postgresql

When the system shutdown unexpectedly, my postgres crashs and i'm unable to connect to it.

What worked for me was:

1˚ Check postgres log:

tail -n 10000 /usr/local/var/log/postgres.log

2˚ Find the PID of postgress, should look like this:

FATAL:  lock file "postmaster.pid" already exists
HINT:   Is another postmaster (PID 707) running in data directory "/usr/local/var/postgres"?

3˚ Kill that process:

kill 707

4˚ Restart your postgres

brew services restart postgresql

After those steps i was able to connect to the database within my rails application.

Solution 7 - Postgresql

If you got no important data to lose :

sudo killAll postgres
brew services restart postgresql

AGAIN : You could get data corrupted by doing this !

do it at your own risk !

Solution 8 - Postgresql

I am using mac and these step work for me:-

step1: cd Library/Application\ Support/Postgres (most commonly your Postgres installation will be located here)

step2: cd var-13 (if you are using version 12 then use cd var-12. Hope got the point)

step3: ls (As you can see among the files you find the postmaster.pid, perfect.)

step4: rm postmaster.pid

When you have removed the stale postmaster.pid file you can restart PostgreSQL and everything should work as normal.

Solution 9 - Postgresql

My OSX laptop had shutdown unexpectedly, and I was getting a stale postmaster.pid error in the PostgresApp. Shutting down my laptop and turning it back on again solved the problem.

Solution 10 - Postgresql

If you have installed postgres with brew then simply run the following command and it will manage everything

 brew services restart postgresql

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionskwidbrethView Question on Stackoverflow
Solution 1 - Postgresqlaronmoshe_mView Answer on Stackoverflow
Solution 2 - PostgresqlSobin SunnyView Answer on Stackoverflow
Solution 3 - PostgresqlBaruch GansView Answer on Stackoverflow
Solution 4 - PostgresqlKamil GosciminskiView Answer on Stackoverflow
Solution 5 - PostgresqlJakub KaniaView Answer on Stackoverflow
Solution 6 - PostgresqlClayton OliveiraView Answer on Stackoverflow
Solution 7 - PostgresqlDiego FaveroView Answer on Stackoverflow
Solution 8 - PostgresqlHEMANTAView Answer on Stackoverflow
Solution 9 - PostgresqlremnantkevinView Answer on Stackoverflow
Solution 10 - PostgresqlAbdulView Answer on Stackoverflow