Peter Brown
Peter Brown

Reputation: 51697

Permission denied running ActiveRecord gem tests in PostgreSQL

I'm having trouble running the ActiveRecord gem tests in PostgreSQL and am getting the following error:

rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:1473:in `initialize': could not connect to server: Permission denied (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I'm able to connect to the server using psql -h localhost and create databases, etc. I'm using http://postgresapp.com/ for the postgresql server. I get the same error when running rake postgresql:build_databases as suggested by the Rails contributing guide.

The rails/activerecord/test/config.yml file has the following settings (all I've changed is the username):

  postgresql:
    arunit:
      username: pete
      min_messages: warning
    arunit2:
      min_messages: warning
      username: pete

Is there another setting I need to configure in config.yml? I've tried specifying a host and empty password, but that doesn't help at all.

Upvotes: 0

Views: 234

Answers (1)

Eelke
Eelke

Reputation: 21993

Your psql is connecting using TCP to localhost, ruby is obviously connecting through a local unix domain socket. Problem with the unix domain socket of postgresql on osx is that not all psql client libraries and database backends agree on the location of the socket.

If you don't pass a -h option to psql it will use a local unix domain socket to. There is a good change it will fail to.

There are two possible solutions for both of which I can't give you details because I do not know ruby on rails and don't have access to a mac right now:

  1. Tell ruby to connect to localhost instead of using the unix domain socket.

  2. Make sure the client library (libpq) used by ruby matches the backend you are running.

Upvotes: 1

Related Questions