1

Trying to get postgres to work with Lion. When I run rake:db create I get:

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"?

There are a lot of SO topics on the same issue but none of solutions have worked for me. Here is what I have tried:

  • Uninstalled & reinstalled the pg gem
  • Installed postgres.app (when I am connected to the local server, pg is still not working)
  • Updated paths file so that usr/local/bin is above usr/bin
  • Changed permissions on var/pgsql_socket to read/write for everyone

What might be a hint is that when I run which psql the result is usr/bin/psql - I believe it is meant to be usr/local/bin/psql, but after editing my paths file directly, I'm not sure why it hasn't changed. Homebrew is also working completely fine for me (no paths issue there).

Any ideas?

EDIT - What's in my database.yml:

development:
adapter: postgresql
encoding: unicode
database: hubbed_development
pool: 5
username: hubbed
password:
host: localhost

test:
adapter: postgresql
encoding: unicode
database: hubbed_test
pool: 5
username: hubbed
password:

production:
adapter: postgresql
encoding: unicode
database: hubbed_production
pool: 5
username: hubbed
password:

EDIT - After running ps aux | grep postgres:

 666   0.0  0.0  2445588    540   ??  Ss    9:42am   0:00.00 postgres: checkpointer process      
 664   0.0  0.1  2445588   3604   ??  S     9:42am   0:00.02 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/angsmith/Library/Application Support/Postgres/var -p5432
 681   0.0  0.0  2434892    540 s000  S+    9:43am   0:00.00 grep postgres
 670   0.0  0.0  2441868    396   ??  Ss    9:42am   0:00.00 postgres: stats collector process      
 669   0.0  0.0  2445720   1524   ??  Ss    9:42am   0:00.00 postgres: autovacuum launcher process      
 668   0.0  0.0  2445588    488   ??  Ss    9:42am   0:00.00 postgres: wal writer process      
 667   0.0  0.0  2445588    524   ??  Ss    9:42am   0:00.01 postgres: writer process  

EDIT - saw that in postgress.app my username was 'postgres'. After updating my database.yml username to postgres and running bundle exec rake db:create:all, I am now getting the following error (different to before):

 rake aborted!
 dlopen(/Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/pg-0.14.1/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libpq.5.5.dylib
 Referenced from: /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/pg-0.14.1/lib/pg_ext.bundle
 Reason: image not found - /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/pg-0.14.1/lib/pg_ext.bundle
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/pg-0.14.1/lib/pg.rb:4:in `require'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/pg-0.14.1/lib/pg.rb:4:in `<top (required)>'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
 /Users/angsmith/hubbedspree/config/application.rb:7:in `<top (required)>'
 /Users/angsmith/hubbedspree/Rakefile:5:in `require'
 /Users/angsmith/hubbedspree/Rakefile:5:in `<top (required)>'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
 /Users/angsmith/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'
 (See full trace by running task with --trace)
SeekingCharlie
  • 607
  • 2
  • 8
  • 19

2 Answers2

4

In my case reinstalling the pg gem fixed it.

0

The entries for development have the host: localhost line but it's missing for the test and production configurations.

It should be included in all configurations, if your 3 databases are on the same server.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156