1

I'm learning rails and following the Ruby on Rails Tutorial Book.

It had an extra challenge and taught me how to use postgreSQL instead of the default SQlite3.

However, since I have changed to postgreSQL my rspec tests fail that did work with SQlite..

I'm running: bundle exec rspec spec/requests/static_pages_spec.rb and it returns:

Failure/Error: Unable to find matching line from backtrace
     PGError:
       could not connect to server: Permission denied
        Is the server running locally and accepting
        connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

This is what I have in my database.yml for testing:

test:
  adapter: postgresql #sqlite3
  database: sample_app #db/test.sqlite3
  pool: 5

Any thoughts? Thanks!!!

8
  • Check your database.yml file has all the updated creds for your postgresql db. Or paste your database.yml here. Commented May 25, 2013 at 5:46
  • You should probably clarify... 1. what you did to "change to postgreSQL", and 2. does the app work properly outside the test environment with your change, and it just fails when running tests? Or does the app fail to work in the browser? Commented May 25, 2013 at 5:47
  • @Trip I just added the test code in my database.yml thanks for your help! Commented May 25, 2013 at 5:48
  • @BobGilmore I changed my database.yml and my gemfile as the tutorial book suggested. Commented May 25, 2013 at 5:50
  • 2
    I see the change you made to your yml file. Did you also install, and/or start, a PostgreSQL server? Because if all you did is edit your .yml file and Gemfile, that's not going to work... Sorry if this is obvious, but gotta check... Commented May 25, 2013 at 5:50

3 Answers 3

1

Are you really not setting your username and password,or have you simply omitted it for the sake of security? It would appear your credentials are missing or incorrect. Ensure you are specifying the correct username and password. You may also want to specify a port.

For example, try the following:

adapter: postgresql 
database: sample_app
hostname: 127.0.0.1
port: 5432
username: USERNAME
password: PASSWORD

You will need to replace USERNAME and PASSWORD with teh values you used when you set up your Postgres server.

Sign up to request clarification or add additional context in comments.

11 Comments

I followed this to setup postgreSQL, nothing said I needed a username and password. http://postgresapp.com/documentation How do I add one? Same with a port, pretty sure it's using the default 5432
@Reuben do you have pg running locally?
I'm using postgreSQL.app (see the link in my previous comment) and it doesn't appear to have a way to set the user and pass on the server..
If postgres server is running, there is almost certainly at least one user set up for it. If not, that's your problem. Make or find a user (probably root, at least) and plug in the credentials into the database.yml template above.
@Reuben That's not in the PostgreSQL documentation, so I assume you mean the postgres.app documentation. Yes, it does; if you built your Pg gem with the correct pg_config on the path you wouldn't have this issue. I explained in lots more detail in my answer and won't repeat that here.
|
0

This is an interesting problem. The error you're getting:

    PGError:
       could not connect to server: Permission denied
        Is the server running locally and accepting
        connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

... indicates that libpq, as used by the Pg gem in Ruby, cannot open the unix socket in /var/pgsql_socket/.s.PGSQL.5432 because of a file system permissions issue. Most likely your user does not have sufficient permissions on /var/pgsql_socket/. If Mac OS X allows sockets themselves to have permissions it could be permissions on /var/pgsql_socket/.s.PGSQL.5432 its self; I use Linux where socket files can't have permissions and don't know if OS X is different.

Try:

ls -ld /var/pgsql_socket/.s.PGSQL.5432
ls -ld /var/pgsql_socket
ls -ld /var

You can usually work around Mac issues with unix sockets and Pg by using a TCP/IP connection. Just specify host as localhost in your database yml; this will cause a TCP/IP network connection to be made rather than a unix socket connection.

It's also possible you're using a libpq that doesn't match the PostgreSQL server you're running. This is common on OS X because Apple installed a customised older version of PostgreSQL by default on some system versions. If that's the case then there's tons of information about the issue on Stack Overflow (search for the tags 'osx', 'rails', 'postgresql') so I won't repeat it here. Using TCP/IP is a workaround, as is specifying host as the unix_socket_path of the running PostgreSQL server.

It's possible that'll fail with a connection refused if PostgreSQL is not in fact running.

1 Comment

@Reuben OK, so the PostgreSQL socket is only readable by the _postgres user. This tells me you're certainly using the wrong libpq, since Postgres.app runs as your user account not as the _postgres user. You're using a different PostgreSQL in Rails, likely the one Apple "helpfully" pre-installed in Mac OS X. Either rebuild the Pg gem against the libpq in postgres.app or run SHOW unix_socket_directory in psql against the Postgres.app PostgreSQL and set your host to the resulting directory. A quick search (I don't have OS X to test with) suggests that's /tmp for Postgres.app.
0

I had to downgrade to postgres 9.2.2, which I discovered here: https://github.com/PostgresApp/PostgresApp/issues/109

Worked like a charm!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.