FATAL ERROR lock file "postmaster.pid" already exists

I recently installed PostGIS on my Mac (El Capitan 10.11.4, Postgres - version 9.5.1) using Homebrew and I follow 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 several hours learning how to handle this, but to no avail.

It is noteworthy that I tried to kill the PID, as recommended in the answer to Superuser - https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists- (in the above example 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 that some people recommended deleting the postmaster.pid file, but it seems to me that maybe I should save this as a last resort ...

Admittedly, I’m not sure how to fix this, because I don’t quite understand what a postmaster is - I’m just starting to learn about all this.

Moving to the Postgres database using the psql db_name works psql db_name fine, for what it's worth it.

+6
source share
4 answers

Postmaster is the main PostgreSQL process. You are trying to run PostgreSQL, which is already working (and you say you can connect to it). Just skip this step of your process.

+3
source

TL DR . Since you can connect to the database, you do not need to start the server again - it is already running.


pg_ctl used to manage the PostgreSQL server. Since your server is already running, your command:

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

It returns an error saying that there is a lock on postmaster.pid - which is true, since there already exists a server using this PID.


There are two ways:

  • The easiest way is to skip this step, your server is already running !
  • Performing an unnecessary operation - stop the server, and then start it again.

You can stop your server:

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

So that you no longer have a lock on postmaster, and you can use your command to run it again.

+7
source

Posting this in case it helps someone else:

I had the same problem as after rebooting my laptop. Which helped me, the following command was run to see which PID was associated with postmaster.pid:

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

The first number that appears will be the PID. Looking in the Activity Monitor, I could see that Postgres is running, but without the PID number that matches the one shown.

Instead of the steps described in the answer to Superuser, I restarted my laptop and then opened a terminal and ran brew services restart postgresql .

This worked without the need to remove postmaster.pid, which I saw in several other posts. Sometimes these are simple solutions that work.

+3
source

This often happens to me on OSx when my system shuts down unexpectedly.

You can simply delete the postmaster.pid file.

cd Library/Application Support/Postgres/var-{postgres-version} and delete the postmaster.pid file

restart Postgres using this command

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

0
source

All Articles