1

Using Postgres 9.2.2, I keep getting this error when I try to start up rails server or run 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"?

This command, when run:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

says server starting, but when I go to check processes, no postgres process is running

My paths are correct

$ which psql
/usr/local/bin/psql
$ which pg_ctl
/usr/local/bin/pg_ctl

If I run this command:

initdb /usr/local/var/postgres -E utf8

It will connect to the socket.... but it also requires me to remove my databases, which is pretty frustrating. This seems happens every time I restart.

Using

  • Postgres 9.2.2
  • Brew
  • OSX Mountain Lion

I found similar threads on stack overflow but none of the solutions seemed to work.

Neal
  • 4,468
  • 36
  • 33
  • This appears to be a common problem on OSX, related to upgrading && packaging. See may answer here: http://stackoverflow.com/a/8482546/905902 BTW: if the server does not start, what does it say in the log? BTW2: did you change locations / directories ? – wildplasser Jan 20 '13 at 18:46
  • You might want to try http://postgresapp.com/ – house9 Jan 20 '13 at 23:22

2 Answers2

3

Screw it. I just installed Postgres.app by Heroku. No more messy issues.

Neal
  • 4,468
  • 36
  • 33
1

I saw this issue arise again once more with someone who actually had Postgres.app installed. Though, it's unclear why his threw this error because I've never seen it before with Postgres.app.

The solution was changing the database.yml file from:

development: &default
  adapter: postgresql
  database: myapp_development
  encoding: utf8
  min_messages: warning
  pool: 5
  timeout: 5000

test:
  <<: *default
  database: myapp_test

To:

development: &default
  adapter: postgresql
  database: myapp_development
  encoding: utf8
  min_messages: warning
  pool: 5
  timeout: 5000
  host: localhost

test:
  <<: *default
  database: myapp_test

Only difference is the "host" line

Neal
  • 4,468
  • 36
  • 33
  • 1
    Sounds like a difference in the socket path compiled into the client library and compiled into the server. Putting "host: localhost" will fix it as it will use a TCP/IP socket, possibly putting "host: /path/to/socketdir" would fix it too, using the unix_socket_dir from the server. – araqnid Jul 19 '13 at 10:56
  • @araqnid thanks for the more in depth answer, I always like to know why my fixes actually work! – Neal Jul 19 '13 at 17:34