Fix the "/tmp/.s.PGSQL.5432" Postgres
Not solved Solved
over 2 years ago

Whenever my Macbook runs out of battery, my Postgresql database is stuck in a weird state and I get this message when launching rails s:

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"?
over 2 years ago

Very simple, just run this in your terminal. You should be good to go!

rm /usr/local/var/postgres/
over 2 years ago

My associate always has that but when I run this command I get no such file or directory :/

about 2 years ago

kind of running into this issue as well.

similar to this:

tried initdb with $ sudo , $ -su $ sudo -u username but always get

initdb: could not change permissions of directory "/usr/local/var/postgres": Operation not permitted

Any idea? Thanks!

about 2 years ago

I bet you upgraded to El Capitan. Then your Homebrew permissinons have been screwed up. You should run this:

sudo chown -R `whoami` /usr/local 
about 2 years ago

indeed! Thanks

over 1 year ago

Après la mis à jour mac os sierra, j'ai du faire cela :

OS X/Homebrew:

Try running postgres -D /usr/local/var/postgres -- it will give you a much more verbose output if postgres fails to start.

In my case, running rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8 removed my old databases and then reinitialized the postgres db schema.

source :

about 2 months ago

perfect, still works! thanks

16 days ago

Hi, I had the same error and none of the answers fixed it. However, following this guide fixed the problem entirely:

Submit your answer