postgresql 致命:没有主机“fe80::1%lo0”的 pg_hba.conf 条目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23348774/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:25:55  来源:igfitidea点击:

FATAL: no pg_hba.conf entry for host "fe80::1%lo0"

sqlruby-on-railsdatabasepostgresqlssl

提问by hellomello

Can someone help me why this is happening when I'm trying to connect to database or rails s?

有人可以帮助我为什么在我尝试连接到数据库时会发生这种情况rails s吗?

In my pg_hba.conf file I have this:

在我的 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     Andrew                                trust
#host    replication     Andrew        127.0.0.1/32            trust
#host    replication     Andrew        ::1/128                 trust

local all all md5

Maybe I'm doing it wrong?

也许我做错了?

Thanks

谢谢

回答by nelsonenzo

I had the same problem. somehow, this line was added to my /etc/hosts file:

我有同样的问题。不知何故,这一行被添加到我的 /etc/hosts 文件中:

fe80::1%lo0    localhost

commenting out or removing that line from /etc/hosts should fix it

从 /etc/hosts 注释掉或删除该行应该可以修复它

sudo vi /etc/hosts
#fe80::1%lo0    localhost

回答by Daniel

I'm on OSX 10.9.3 and Postgres 9.3.4.

我在 OSX 10.9.3 和 Postgres 9.3.4 上。

I've managed to resolve this problem in the following way:

我设法通过以下方式解决了这个问题:

First find your pg_hba.conffile by starting up psql with psql -h 127.0.0.1and executing SHOW hba_file;:

首先pg_hba.conf通过启动 psqlpsql -h 127.0.0.1并执行SHOW hba_file;以下命令来找到您的文件:

              hba_file
-------------------------------------
 /usr/local/var/postgres/pg_hba.conf
(1 row)

Now add the following line to pg_hba.conf:

现在将以下行添加到pg_hba.conf

host    all             all             fe80::1%lo0/128         trust

and reload the configuration via select pg_reload_conf();within psql.

并通过select pg_reload_conf();内重新加载配置psql

Now you should be able to connect via psql -h fe80::1%lo0.

现在您应该可以通过psql -h fe80::1%lo0.

回答by Craig Ringer

Oo, that's an interesting one.

哦,这是一个有趣的。

Assuming you're connecting to localhost(you didn't say and didn't show your database.yml), it appears that localhostis resolving to an IPv6 link-local address with zone index.

假设您要连接到localhost(您没有说也没有显示您的database.yml),似乎localhost正在解析为带有区域索引的 IPv6 链接本地地址

If you use ::1or 127.0.0.1it should work.

如果您使用::1127.0.0.1它应该工作。

This is very likely an operating system misconfiguration or bug, so lots more detail (see comment above) should be added to the question if you want any concrete advice on that.

这很可能是操作系统配置错误或错误,因此如果您想要任何具体的建议,应该在问题中添加更多详细信息(请参阅上面的评论)。

回答by NoahP

For me, the cause was calling sudo rails server -p 80.

对我来说,原因是调用sudo rails server -p 80.

I bound the rails server to port 80 so that I wouldn't have to specify a port in the url localhost:3000during development. This appears to write fe80::1%lo0?localhostto my /etc/hostsfile.

我将 rails 服务器绑定到端口 80,这样我就不必localhost:3000在开发过程中在 url中指定端口。这似乎写入fe80::1%lo0?localhost我的/etc/hosts文件。

Try commenting out the line in your hosts file, then running rails s -p 3000

尝试注释掉主机文件中的行,然后运行 rails s -p 3000

回答by Jayaprakash

Actually,

实际上,

The same error occurs for me when I execute pg_dumpcommand to take backup of my server database (external) like below

当我执行pg_dump命令来备份我的服务器数据库(外部)时,我会发生同样的错误,如下所示

'/Applications/Postgres.app/Contents/Versions/9.3/bin'/pg_dump -d "<database_name>" -h <server_name> -U <db_user_name> -f <destination_path>

I solved it (work around) by replacing my <server_name>to my actual server IP (10.1.0.18).

我通过将我的替换<server_name>为我的实际服务器 IP ( 10.1.0.18)来解决它(变通)。

So the issue here is my system didn't understand the <server_name>host.

所以这里的问题是我的系统不理解<server_name>主机。

It might solve permanently when you add <server_name>host in /private/etc/hosts file.

当您<server_name>在 /private/etc/hosts 文件中添加主机时,它可能会永久解决。

回答by user3414554

Another variant: if IPv6 is not used in the network, you can just disable it. On Windows IPv6 service also can be disabled.

另一种变体:如果网络中未使用 IPv6,您可以禁用它。在 Windows 上也可以禁用 IPv6 服务。