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.
you do clean up for system. In this case, Brew’s PostgreSQL .pid file is at
$ sudo rm /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.