Postgresql“没有 pg_hba.conf 条目”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17462331/
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
Postgresql "no pg_hba.conf entry" error
提问by jyli7
I'm setting up my local postgresql database for a rails project (that I'm joining), and have done the following:
我正在为一个 rails 项目(我正在加入)设置我的本地 postgresql 数据库,并完成了以下操作:
- Installed postgres
- Added/bundled 'pg' gem
- Created a db user named "foobar"
- Created a db named "foobar_development"
- 安装 postgres
- 添加/捆绑“pg”宝石
- 创建了一个名为“foobar”的数据库用户
- 创建了一个名为“foobar_development”的数据库
The rails app comes with a rake db:migrate task. When I run this task, I get the following error output:
rails 应用程序带有 rake db:migrate 任务。当我运行这个任务时,我得到以下错误输出:
FATAL: no pg_hba.conf entry for host "::1", user "foobar", database "foobar_development", SSL off
I found a pg_hba.conf file in the following location:
我在以下位置找到了一个 pg_hba.conf 文件:
/usr/local/var/postgres
/usr/local/var/postgres
Here's the relevant part of the pg_hba.conf file:
这是 pg_hba.conf 文件的相关部分:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication jimmyli trust
#host replication jimmyli 127.0.0.1/32 trust
#host replication jimmyli ::1/128 trust
I am using the postgres that came with my Mac (version 9.2.4), although I'm worried I might have installed another version of it somewhere else (and ought to remove it - anyway I can check this?). I am also using Postgres.app to run psql. (http://postgresapp.com/).
我正在使用 Mac(版本 9.2.4)附带的 postgres,虽然我担心我可能在其他地方安装了它的另一个版本(应该删除它 - 无论如何我可以检查这个?)。我也在使用 Postgres.app 来运行 psql。(http://postgresapp.com/)。
I think my pg_hba.conf file ought to work correctly (since I'm giving all users access to all dbs), so I wonder if there's another pg_hba.conf file out there, and that I'm looking at the wrong one/one that's not being used. How can I test this hypothesis?
我认为我的 pg_hba.conf 文件应该可以正常工作(因为我让所有用户都可以访问所有 dbs),所以我想知道那里是否还有另一个 pg_hba.conf 文件,而且我正在查看错误的一个/一个没有被使用。我怎样才能检验这个假设?
回答by jyli7
Got it! Looks like I was looking at the wrong/irrelevant pg_hba.conf file. To find the right one, I logged into the db with psql and ran "SHOW hba_file"
知道了!看起来我正在查看错误/不相关的 pg_hba.conf 文件。为了找到正确的,我用 psql 登录数据库并运行“SHOW hba_file”
This gave me the path to the relevant file, which in my case was:
这给了我相关文件的路径,在我的情况下是:
/Library/PostgreSQL/9.1/data
/图书馆/PostgreSQL/9.1/数据
I then added the right lines (see my question) to this question, and everything worked!.
然后我在这个问题中添加了正确的行(见我的问题),一切正常!
回答by bma
Did you reload postgresql after making the change to your pg_hba.conf file? Try logging into the db as a superuser and issue select pg_reload_conf();
to reload the pg_hba.conf and postgresql.conf files.
对 pg_hba.conf 文件进行更改后是否重新加载了 postgresql?尝试以超级用户身份登录数据库并发出select pg_reload_conf();
重新加载 pg_hba.conf 和 postgresql.conf 文件的问题。
回答by hd1
回答by Lieblingsfarbe
Set the following environment variable in command line to require SSL for Postgres connections:
在命令行中设置以下环境变量以要求 Postgres 连接使用 SSL:
$ export PGSSLMODE=require