postgresql 无法访问 postgres 文件 pg_hba.conf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13665038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't access postgres file pg_hba.conf
提问by Jakxna360
I am getting this error when i run db:create:
运行 db:create 时出现此错误:
FATAL: Peer authentication failed for user "wandrr"
/home/Hyman/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
/home/Hyman/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
/home/Hyman/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
/home/Hyman/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
/home/Hyman/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/home/Hyman/.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/Hyman/.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/Hyman/.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/Hyman/.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/Hyman/.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/Hyman/.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/Hyman/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/Hyman/.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/Hyman/.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/Hyman/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/Hyman/.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/Hyman/.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/Hyman/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/home/Hyman/.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}
So I figured out that I have to edit pg_hba.conf The problem is... It won't open. It keeps telling me I don't have permission to use this file. So how do I get permission? I'm running ubuntu 12.10 and rails 1.9.3 and postgres 9.1
所以我想我必须编辑 pg_hba.conf 问题是......它不会打开。它一直告诉我我没有使用这个文件的权限。那么我如何获得许可?我正在运行 ubuntu 12.10 和 rails 1.9.3 和 postgres 9.1
回答by Craig Ringer
First note down the location of pg_hba.conf
on your system. If you don't know it but you can connect, connect to Pg with PgAdmin-III or psql
and run:
首先记下pg_hba.conf
在您的系统上的位置。如果您不知道但可以连接,请使用 PgAdmin-III 连接到 Pg 或psql
运行:
SHOW hba_file;
to get the location of pg_hba.conf
. It's location is pretty standard; on Ubuntu it'll be in /etc/postgresql/[major.minor]/main/pg_hba.conf
eg /etc/postgresql/9.1/main/pg_hba.conf
. On most other distros it'll be under /var/lib/pgsql/
or /var/lib/postgresql
, either directly or in versioned directory.
以获取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
直接或者在版本控制目录。
To edit this file you must specify the full path or change directory to its location first. Say:
要编辑此文件,您必须先指定完整路径或将目录更改为其位置。说:
sudo vi /etc/postgresql/9.1/main/pg_hba.conf
If you prefer a friendlier text editor:
如果您更喜欢更友好的文本编辑器:
sudo nano /etc/postgresql/9.1/main/pg_hba.conf
or replace "nano" with your preferred editor, like gedit
.
或者用你喜欢的编辑器替换“nano”,比如gedit
.
Once you save your changes, remember to reload the PostgreSQL service to have them take effect. On Ubuntu you want:
保存更改后,请记住重新加载 PostgreSQL 服务以使它们生效。在 Ubuntu 上你想要:
pg_ctlcluster 9.1 main reload
回答by Valerie Anderson
Following Crag's advice worked well.
遵循 Crag 的建议效果很好。
For his last step, you have to sudo into the database superuser in order to get the PostgreSQL service to reload:
对于他的最后一步,您必须 sudo 进入数据库超级用户才能重新加载 PostgreSQL 服务:
sudo -u postres pg_ctlcluster 9.1 main reload
These steps also work for Debian Sid systems.
这些步骤也适用于 Debian Sid 系统。
回答by Chris Halcrow
To edit pg_hba.conf
, you can try editing as the postgres
user:
要编辑pg_hba.conf
,您可以尝试以postgres
用户身份进行编辑:
switch to the
postgres
usersudo su postgres
run
psql
SHOW hba_file;
as a query in psql to get the locationnano *the file location*
(notsudo nano
as that will attempt the editing operation as the root user)
切换到
postgres
用户sudo su postgres
跑
psql
SHOW hba_file;
作为 psql 中的查询来获取位置nano *the file location*
(不是sudo nano
那样会尝试以 root 用户身份进行编辑操作)