Ruby on Rails:运行rake后与PG的连接错误:db migrate

时间:2014-10-25 05:26:15

标签: ruby-on-rails ruby git postgresql

最近我分叉并克隆了我正在贡献的回购,当我运行rails s时,我没有错误,但是当我运行rake db:migrate时,我得到了这个。

    rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我和其他有同样问题的人检查了一些其他线程但是他们的解决方案对我来说没有任何运气。

我尝试卸载并重新安装PG以及删除.PID文件,但它看起来不像我似乎有。

任何线索,指示或建议?提前谢谢。

1 个答案:

答案 0 :(得分:2)

这意味着,database.yml目录中的config/文件未针对您的环境正确设置,很可能是development,因为它是默认设置,或者您没有postgresql跑步。

如果您没有postgresql正在运行,请安装或启动它。您可以使用以下任一方法检查postgresql:

sudo service postgresql status

或     ps -ef | grep postgres

如果您的postgresql运行正常,请检查您的database.yml文件并进行相应的编辑,最可能是:

development:
  adapter: postgresql
  encoding: unicode
  database: database_name
  host: localhost
  username: user_name
  password: password