提问人:Jakxna360 提问时间:12/2/2012 最后编辑:TarHaldaJakxna360 更新时间:10/10/2022 访问量:45631
无法访问 postgres 文件 pg_hba.conf
can't access postgres file pg_hba.conf
问:
当我运行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。
答:
31赞
Craig Ringer
12/2/2012
#1
首先记下系统上的位置。如果您不知道,但可以连接,请使用 PgAdmin-III 连接到 Pg 或运行:pg_hba.conf
psql
SHOW hba_file;
获取 的位置。它的位置相当标准;在 Ubuntu 上,它将在 例如.在大多数其他发行版上,它将直接或在版本化目录中位于 或 下。pg_hba.conf
/etc/postgresql/[major.minor]/main/pg_hba.conf
/etc/postgresql/9.1/main/pg_hba.conf
/var/lib/pgsql/
/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
评论
0赞
Connor Leech
11/12/2013
当我这样做时,除了 pg_hba.conf 之外,我的目录还添加了一个 pg_hba.conf~。编辑 pg_hba.conf 文件的最佳方法是什么?sudo gedit pg_hba.conf
0赞
Nezir
5/11/2019
哦,伙计,在 1:30 小时后寻找解决方案,这对我有帮助!谢谢!
1赞
Valerie Anderson
3/18/2015
#2
遵循 Crag 的建议效果很好。
对于他的最后一步,您必须 sudo 进入数据库超级用户才能重新加载 PostgreSQL 服务:
sudo -u postres pg_ctlcluster 9.1 main reload
这些步骤也适用于 Debian Sid 系统。
1赞
Chris Halcrow
12/16/2019
#3
要编辑,您可以尝试以用户身份进行编辑:pg_hba.conf
postgres
切换到用户
postgres
sudo su postgres
跑
psql
SHOW hba_file;
作为 psql 中的查询来获取位置nano *the file location*
(不会,因为这将尝试以root用户身份进行编辑操作)sudo nano
评论
sudo vi pg_hba.conf
pg_hba.conf
sudo vi pg_hba.conf
pg_hba.conf
sudo vi /etc/postgresql/9.1/main/pg_hba.conf
SHOW hba_file;
psql