我跑步时遇到问题:

rake db:create:all

我现在有:
$ psql --version
psql (PostgreSQL) 9.3.0

$ which psql
/Applications/Postgres.app/Contents/MacOS/bin/psql

得到:
$ rake db:create:all
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"?
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `new'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `connect'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:324:in `initialize'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/Users/stephanecedroni/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
.....
.....

尝试卸载并重新安装pggem,但仍然无法工作。
先是试图跟随瑞安·贝茨的剧本,但遇到了一些问题,然后检查了Heroku Postgres建议设置此路径:
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

最佳答案

可能rake试图连接到/var/pgsql_socket/.s.PGSQL.5432,但域套接字实际上在其他地方。我的在/tmp/.s.PGSQL.5432。你可以试试这些:
在database.yml中指定host: localhost。例如:

development:
  host: localhost
  # other stuff

或者
/var/pgsql_socket/中创建指向.s.PGSQL.5432实际所在位置的符号链接。
mkdir /var/pgsql_socket
ln -s /tmp/.s.PGSQL.5432 /var/pgsql_socket/.s.PGSQL.5432

你可能还得去查一下链接。我不确定你是否也需要链接.s.PGSQL.5432.lock。
第一种选择要容易得多。不确定是哪一个更好。

关于ruby-on-rails - Postgresql Rails的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19246793/

10-15 21:31