18 Oct 2015

Rails cannot connect to Postgres db

A project that was working on my laptop just fine a few months ago, today throws this error:

PG::ConnectionBad - could not connect to server: No such file or directory Is
the server running locally and accepting connections on Unix domain socket

I’m sure Postgres is running as I can connect directly using psql and other rails projects are using it just fine.

I updated the pg gem but it didn’t work. After some googling, I fixed it by adding the following line to my /config/database.yml:

host: localhost

Not sure why this happened as other projects don’t have this line.