When I previously used to use Postgresql.app I received the error $ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? pretty frequently, so I decided to switch to the homebrew version.

I haven't had this issue ever since, until this afternoon. I tried unloading/loading it with the OS X launch daemon as well as restarted the computer with no luck.

The problem appeared to be a .pid file in /usr/local/var/postgres and it was very easy to solve, once I found out.

First, verify that this is indeed the issue:

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

If the output is anything else than a postgresql process, you are indeed affected by the same issue. To tell postgres that this is indeed not itself, simply remove or move the file - e.g.

mv /usr/local/var/postgres/postmaster.pid /usr/local/var/postgres/postmaster-old.pid

If it indeed fixes your issue, go ahead and delete the old pid file

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

I hope it worked as well for you, as it did for me!

If you liked the article, you can follow me on twitter.