# Dealing with 'psql: could not connect to server' on OS X

Stuck with 'psql: could not connect to server: No such file or directory' on macOS Homebrew Postgres? Here's the stale postmaster.pid fix.

Published: 2014-01-07
Source: https://www.kristian.io/os/x,/mac,/homebrew/2014/01/07/postgresql-error-on-mac-os-x.html/

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:

```bash
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.

```bash
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

```bash
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](https://twitter.com/oellegaard).
