我在运行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。问题是它打不开。它一直告诉我没有权限使用这个文件。那么我如何获得权限呢?我运行的是ubuntu12.10,rails1.9.3,postgres 9.1。
3条答案
按热度按时间f0ofjuux1#
首先记下
pg_hba.conf
在系统中的位置。如果您不知道它,但可以连接,请使用PgAdmin-III或psql
连接到Pg并运行:来得到
pg_hba.conf
的位置。它的位置是相当标准的;在Ubuntu上,它将位于/etc/postgresql/[major.minor]/main/pg_hba.conf
,例如/etc/postgresql/9.1/main/pg_hba.conf
。在大多数其他发行版上,它将位于/var/lib/pgsql/
或/var/lib/postgresql
下,直接或在版本目录中。要编辑此文件,您必须先指定完整路径或将目录更改到其位置。
如果您喜欢更友好的文本编辑器:
或者将“nano”替换为您喜欢的编辑器,如
gedit
。保存更改后,请记住重新加载PostgreSQL服务以使更改生效。在Ubuntu上,您需要:
kzipqqlq2#
听从克雷格的建议效果很好。
对于他的最后一步,您必须sudo进入数据库超级用户,以便重新加载PostgreSQL服务:
这些步骤也适用于Debian Sid系统。
wlzqhblo3#
要编辑
pg_hba.conf
,您可以尝试以postgres
用户身份进行编辑:postgres
用户sudo su postgres
psql
SHOW hba_file;
作为psql中的查询以获取位置nano *the file location*
(* 不是 *sudo nano
,因为它将尝试以root用户身份执行编辑操作)