Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres rake db:migrate fails with access denied error

I'm using MacOSX Lion, ruby 1.9.2, Rails 3.1.2 and postgres 9.0.4

I did a rake db:migrate on my app using postgres. It failed with access denied error.

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
rake aborted!
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"?

I have checked whether server is running and it is running ok. I could connect successfully to my db using

psql -Umyuser myapp_development
psql -Umyuser myapp_test

While creating a new PG user, it never asked me for a password and so I didn't give password for that user myuser anywhere.

Here is my database.yml file.

development:
  adapter: postgresql
  encoding: utf8
  database: myapp_development
  username: pgguy

test:
  adapter: postgresql
  encoding: utf8
  database: myapp_test
  username: pgguy

production:
  adapter: postgresql
  encoding: utf8
  database: myapp_production

what should I do to connect to it from my rails app?

like image 466
Anand Avatar asked Nov 20 '11 02:11

Anand


1 Answers

Adding host to my database.yml file solved this.

development:
  adapter: postgresql
  encoding: utf8
  database: myapp_development
  username: myuser
  host: localhost

test:
  adapter: postgresql
  encoding: utf8
  database: myapp_test
  username: myuser
  host: localhost

production:
  adapter: postgresql
  encoding: utf8
  database: myapp_production

I referred to this thread for a solution: Repairing Postgresql after upgrading to OSX 10.7 Lion

like image 65
Anand Avatar answered Oct 19 '22 06:10

Anand