PG::ConnectionBad: could not connect to server: No such file or directory

rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432”?

I ran into this issue recently when running rake db commands on a new rails project with a postgres db.

Solution:

Add the below line of code to your config/database.yml file.

default: &default
  host: localhost

What happened?

From what I understand my application has a tunnel connecting to my postgres database. The connection originally was through my linux system though what’s needed is a SSH tunnel to the database host.

More details here:

https://support.cloud.engineyard.com/hc/en-us/articles/205408088-Access-Your-Database-Remotely-Through-an-SSH-Tunnel#topic1