Kevin L.
Kevin L.

Reputation: 1471

Rails cannot find my Postgres server on Mac OS X / PG::ConnectionBad: could not connect to server

I am following a rails tutorial and am trying to do a simple migration but my rails app is having trouble finding my Postgres server (I'm using mac OS X).

When I run bundle exec rake db:migrate on my rails app, I get the following 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 "/var/pgsql_socket/.s.PGSQL.5432"?

When I type sudo lsof -i tcp:5432 I get the output

COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
postgres  73 postgres    4u  IPv6 0xd0338068e4dc128d      0t0  TCP *:postgresql (LISTEN)
postgres  73 postgres    5u  IPv4 0xd0338068e4852e55      0t0  TCP *:postgresql (LISTEN)

So Postgres is clearly running on port 5432.

What could be the solution?

Upvotes: 0

Views: 628

Answers (1)

Kevin L.
Kevin L.

Reputation: 1471

Solved:

add

host: localhost 

to the database.yml file

Upvotes: 4

Related Questions