Postgres not allowing localhost but works with 127.0.0.1
如果我说
1 2 3 4 5 6 7 8 9 | [root@5d9ca0effd7f opensips]# psql -U postgres -h localhost -W Password FOR USER postgres: psql: FATAL: Ident authentication failed FOR USER"postgres" [root@5d9ca0effd7f opensips]# psql -U postgres -h 127.0.0.1 -W Password FOR USER postgres: psql (8.4.20) TYPE"help" FOR help. postgres=# |
我的
1 2 3 4 5 6 7 8 9 10 | # TYPE DATABASE USER CIDR-ADDRESS METHOD #"local" IS FOR Unix DOMAIN socket connections ONLY LOCAL ALL ALL trust LOCAL ALL ALL ident # IPv4 LOCAL connections: host ALL ALL 127.0.0.1/32 trust host ALL ALL 127.0.0.1/32 ident # IPv6 LOCAL connections: host ALL ALL ::1/128 ident |
如果我添加以下行,则Postgres服务
1 2 | host ALL ALL localhost ident host ALL ALL localhost trust |
那有什么不对?
更新
我的
1 2 3 4 5 6 7 8 | [root@5d9ca0effd7f opensips]# cat /etc/hosts 172.17.0.2 5d9ca0effd7f 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters |
在pg_hba.conf中,第一个匹配计数。每个文件:
The first record with a matching connection type, client address,
requested database, and user name is used to perform authentication.
There is no"fall-through" or"backup": if one record is chosen and
the authentication fails, subsequent records are not considered. If no
record matches, access is denied.
请注意相反的顺序:
1 2 | host ALL ALL 127.0.0.1/32 trust host ALL ALL 127.0.0.1/32 ident |
但:
1 2 | host ALL ALL localhost ident host ALL ALL localhost trust |
好吧,如果你真的"添加"你写的那些行,那么根本就没有任何影响。但如果你更换线路,就有。
在第一种情况下,您将获得
PostgreSQL assumes that anyone who can connect to the server is
authorized to access the database with whatever database user name
they specify (even superuser names)
但在第二种情况下,您将获得
如果您实际使用的是过时的版本8.4,请转到8.4的旧手册。您知道8.4已经在2014年达到EOL并且不再受支持了吗?考虑升级到当前版本。
更多:
- 使用不带密码的psql命令运行批处理文件
问题
Postgres在指定
但是,当指定
答案
因此答案是修改
1 2 | # IPv6 LOCAL connections: host ALL ALL ::1/128 trust |
记住在进行配置更改后重新启动Postgres服务。