Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just reinstalled postgres via brew install postgres

I ran initdb /usr/local/var/postgres -E utf8 but got this:

The files belonging to this database system will be owned by user "atal421".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".

so, I rm -rf the postgres folder and ran it again:

 initdb /usr/local/var/postgres -E utf8

it said everything was okay:

Success. You can now start the database server using:

    postgres -D /usr/local/var/postgres

so, I ran that command and got:

postgres -D /usr/local/var/postgres

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

Now when I look at my Activity Monitor I can see 6 instances of postgress.

How do I fix this?

share|improve this question
You probably see one instance of postgres with a postmaster and five utility backends. PostgreSQL is a multi-process architecture. –  Craig Ringer Feb 17 '13 at 23:39

4 Answers 4

You already had PostgreSQL installed, and you deleted the data dir without stopping the running server. So you now have some orphan PostgreSQL server processes that are managing data files that've been deleted, so they're no longer accessible in the file system and will be fully deleted when the last open file handle to them is closed. You can't use pg_ctl to shut the server down like normal because you've deleted the cluster datadir, so you must simply kill the processes. Kill the postmaster (do not use kill -9, just an ordinary kill will do) and the rest will shut down too.

You will then be able to start a new server in the datadir against the freshly initdb'd data.

It is highly likely that you will experience conflicts down the track unless you uninstall the other older version of PostgreSQL.

In a nutshell:

cat /usr/local/var/postgres/

Note down the number on the first line, which is the pid of the postmaster. Kill the postmaster process with the following command, replacing 'PID' with the number you have noted down. Again, do not use kill -9 or kill -KILL, just use a plain kill, i.e. a SIGTERM:

kill PID

share|improve this answer
this worked for me! –  Tone Nov 26 '13 at 6:53
thank you :) :) :) –  vaughan Jan 31 '14 at 13:41
This works. Had a problem where I emptied my trash and it seems some data files probably were in there...not sure how, but they were. Once I killed the old process it worked fine. –  Dan L Jun 4 '14 at 15:30
yeah. that was spot on. –  Amos Folarin Jun 2 at 15:52

Another possibility is that you had a hard shutdown and the postgres process died without cleaning up its pid. So if another process -- or none at all -- is running on that port, just delete the pid file and postgres will soon start up fine.

To find out if another process is running on that port, you can do

ps wax | grep $pid

where pid is the first line of that file.

Then run

tail -f /usr/local/var/postgres/server.log

to see if it worked. You should see

FATAL:  lock file "" already exists
HINT:  Is another postmaster (PID 933) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "" already exists
HINT:  Is another postmaster (PID 933) running in data directory "/usr/local/var/postgres"?
LOG:  database system was interrupted; last known up at 2014-05-25 09:41:32 PDT
LOG:  database system was not properly shut down; automatic recovery in progress

(or at least that's what I just saw after I did the above :-) )

share|improve this answer
This was the case for me. I had another process coincidentally running on the same PID as the file was pointing to. This was several days after an unclean shutdown (laptop installation of Postgres on OSX via homebrew). –  Jesse Buchanan Oct 7 '14 at 3:04

I tried all of this to no avail after upgrading to Yosemite broke my postgres (installed via homebrew).

Then I stumbled on this blog post:

First I needed to create the missing directories that were apparently wiped out during the upgrade (thanks Apple!).

$ cd /usr/local/var/postgres

$ mkdir {pg_tblspc,pg_twophase,pg_stat_tmp}

Then just start postgres again using the normal homebrew launch sequence:

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Thanks Ruckus Notes for helping solve my problem. Hopefully it helps you as well.

share|improve this answer

I received this error after, I think, my computer crashed. PostgreSQL couldn't even start because of this error so killing the process wasn't the solution. I simply backed-up and then deleted the file and then the error stopped and PG was able to start again.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.