FATAL ERROR lock file “postmaster.pid” already exists


FATAL ERROR lock file “postmaster.pid” already exists



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,


kill 208



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.


psql db_name




4 Answers
4



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.





Oh! Thank you. It seems obvious to me now, but I'm just finding my way here. Much appreciated.
– skwidbreth
Apr 5 '16 at 20:31



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



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


pg_ctl


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.


postmaster.pid



There are two ways:



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.





Oh man, thank you so much. I really appreciate your help. Someday, I'll be a PostGIS master... but until then...
– skwidbreth
Apr 5 '16 at 20:31





PostGIS had actually nothing to do with your problem :-) It's strictly Postgres service issue.
– Kamil G.
Apr 5 '16 at 20:32






I dig - just making sure I put everything on the table.
– skwidbreth
Apr 5 '16 at 20:39



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.



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



You can just remove the file postmaster.pid.


postmaster.pid


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



and remove the postmaster.pid file



restart the Postgres by using this command


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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy