9

运行 db:create 时出现此错误:

FATAL:  Peer authentication failed for user "wandrr"
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/home/jack/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/home/jack/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
....Edit out 40 more of these warnings...
/home/jack/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/home/jack/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"wandrr_test", "pool"=>5, "username"=>"wandrr", "password"=>nil}

所以我发现我必须编辑 pg_hba.conf 问题是......它不会打开。它一直告诉我我没有使用此文件的权限。那么如何获得许可呢?我正在运行 ubuntu 12.10 和 rails 1.9.3 和 postgres 9.1

4

3 回答 3

27

首先记下pg_hba.conf系统上的位置。如果您不知道但可以连接,请使用 PgAdmin-III 连接到 Pg 或psql运行:

SHOW hba_file;

获取 的位置pg_hba.conf。它的位置非常标准;在 Ubuntu 上,它会在/etc/postgresql/[major.minor]/main/pg_hba.conf例如/etc/postgresql/9.1/main/pg_hba.conf. 在大多数其他发行版上,它将位于/var/lib/pgsql/or下/var/lib/postgresql,直接或在版本化目录中。

要编辑此文件,您必须先指定完整路径或将目录更改为其位置。说:

sudo vi /etc/postgresql/9.1/main/pg_hba.conf

如果您喜欢更友好的文本编辑器:

sudo nano /etc/postgresql/9.1/main/pg_hba.conf

或将“nano”替换为您喜欢的编辑器,例如gedit.

保存更改后,请记住重新加载 PostgreSQL 服务以使它们生效。在 Ubuntu 上你想要:

pg_ctlcluster 9.1 main reload
于 2012-12-02T08:26:17.393 回答
1

遵循 Crag 的建议效果很好。

对于他的最后一步,您必须 sudo 进入数据库超级用户才能重新加载 PostgreSQL 服务:

sudo -u postres pg_ctlcluster 9.1 main reload

这些步骤也适用于 Debian Sid 系统。

于 2015-03-18T14:21:24.550 回答
1

要编辑pg_hba.conf,您可以尝试以postgres用户身份进行编辑:

  • 切换到postgres用户

    sudo su postgres

  • psql

  • SHOW hba_file;作为 psql 中的查询以获取位置
  • nano *the file location*不会 sudo nano以root用户身份尝试编辑操作)
于 2019-12-16T06:16:55.390 回答