0

Possible Duplicate:
PostgreSQL Permission denied Error on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432” - Lion Server 10.7.3 or Lion Server 10.7.4

I'm using postgres as my backend database for Rails, but it has stopped working due to a misconfiguration problem, but I cannot see what it is.

My version of postgres is 9.1.4, and is installed in /usr/bin

I'm running ruby version 1.9.3, but I have to switch to it manually in rvm, since the default 1.8.7 is what comes up.

I'm running Rails 3.2.8

My config file pg_hba.conf looks like:

# "local" is for Unix domain socket connections only
local   all         all                               md5
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

Most lines in postgres.conf file are commented out, save for a few innocuous lines like:

log_destination = 'stderr'
listen_addresses = '*'   
port = 5432                             
max_connections = 100                  

I also installed the 'Postgres App' for Mac (see postgresapp.com/documentation), which it says is running and listening on port 5432.

When I run ps -ax | grep post I see:

1088 ??         0:00.08 com.heroku.postgres-service
 1135 ??         0:00.29 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/rickc/Library/Application Support/Postgres/var -p5432
 1137 ??         0:01.14 postgres: writer process      
 1138 ??         0:00.78 postgres: wal writer process      
 1139 ??         0:00.20 postgres: autovacuum launcher process      
 1140 ??         0:00.26 postgres: stats collector process      

But when I try to start rails connect at localhost:3000, I get this error message: PG::Error

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've tried to examine the previous posts here, and the postgres documentation of course, cannot quite see what's misconfigured here; any help much appreciated...

Community
  • 1
  • 1
rixter
  • 1,237
  • 3
  • 19
  • 32
  • 1
    Have you checked if the unix domain socket is located at `var/psql_socket/` ? (which is a strange place, BTW) – wildplasser Nov 27 '12 at 00:02
  • 1
    Did you read the rails sections on the [postgresapp](http://postgresapp.com/documentation) page mentioned in the question? According to the error message, you did not set the db host to `localhost` in `config/database.yml` as suggested in this page. – Daniel Vérité Nov 27 '12 at 00:56
  • 1
    about `/var/pgsql_socket`: it's a MacOS X path. The problem that is so common on MacOS X is that programmers use client setups that are not configured by default to talk to their server setups, because they are several of them available for download. They think that "installing postgresql" is sufficient and don't realize they're responsible for connecting the dots between the client part and the server part. – Daniel Vérité Nov 27 '12 at 01:05
  • There is nothing in /var/psql_socket. Appears to be another misconfiguration. – rixter Nov 27 '12 at 21:20
  • See also here: http://stackoverflow.com/questions/13114411/postgresql-socket-error-when-running-djangos-syncdb-mac-os-10-7-5 and here: http://stackoverflow.com/questions/13114411/postgresql-socket-error-when-running-djangos-syncdb-mac-os-10-7-5 and here: http://stackoverflow.com/questions/11443738/postqresql-in-rails-how-do-i-make-the-server-run-locally-and-accept-connections –  Nov 27 '12 at 21:32
  • Nice post...kind of sent me down the rabbithole though...now I have to learn all about "launchd" and launchctl! – rixter Nov 28 '12 at 00:03

1 Answers1

-1

This is a postgres issue, not a rails/ruby issue.

To prove it to yourself, open a terminal and do

psql -U username -W db_name

Where username is your username and db_name is the name of the database.

You should get the "couldn't connect to server" error.

Here's what you do:

  • tail your postgres log in a terminal window
  • Restart postgres and watch the terminal

You will see the problem in the log. If you can't figure out the problem, post the relevant part of your log and we'll take a look.

BryanH
  • 5,826
  • 3
  • 34
  • 47