--- layout: post status: publish published: true title: psql could not connect to server author: display_name: sipp11 login: sipp11 email: sipp11@gmail.com url: '' author_login: sipp11 author_email: sipp11@gmail.com wordpress_id: 978 wordpress_url: http://blog.10ninox.com/?p=978 date: '2014-04-13 02:54:27 +0700' date_gmt: '2014-04-12 19:54:27 +0700' categories: - osx tags: - error ---
There are a few problems when you think of Homebrew on OSX. This is a problem that has nothing to do with Brew at all.
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"?
When you find this error message while getting back from system crash, freeze, or any unexpected shutdown, it only means that there is a dirty PID file pointing out the somewhere empty. Basically every daemons will create .pid to store process number, socket and such, so when need, it will be able to do it right and delete right after shutting down the daemons. However, when unexpected shutdown occurs, no time for cleaning up .pid file, that's where problems start. Everyone will think that the daemon is running (its .pid file exists) and asking for something, surely that .pid file can only lead to false route.
Solution: you do clean up for system. In this case, Brew's PostgreSQL .pid file is at /usr/local/var/postgres/postmaster.pid
$ sudo /usr/local/var/postgres/postmaster.pid
Then you can start your postgres again. It's the same with every other daemons; you just need to find its PID file.