问题描述
在pg_hba.conf中,第 计数。每个文档:
具有匹配的连接类型,客户端地址,请求的数据库和用户名的第一条记录用于执行身份验证。没有“失败”或“备份”:如果选择了一条记录并且验证失败,则不会考虑后续记录。如果没有记录匹配,则拒绝访问。
请注意 :
host all all 127.0.0.1/32 trust
host all all 127.0.0.1/32 ident
但:
host all all localhost ident
host all all localhost trust
将更改保存到后,请记住要pg_hba.conf
。(无需重新启动。)手册:
该
pg_hba.conf
文件被读取在启动时和当主服务器处理一个SIGHUP信号。如果您在活动系统上编辑文件,则需要向邮局局长发信号(使用pg_ctl reload
,调用sql函数pg_reload_conf()
或使用kill -HUP
),以使其重新读取文件。
如果您确实像您写的那样“添加”了这些行,则根本不会有任何效果。但是,如果您 管线,则存在。
在第一种情况下,您将获得trust
身份验证方法,这是一种开放策略。每个文档:
但是在第二种情况下,您将获得ident
身份验证方法,该方法必须正确设置才能起作用。
另外,正如Cas稍后指出的那样,它localhost
涵盖了IPv4和IPv6,而127.0.0.1/32
仅适用于IPv4。如果使用IPv6,则是一个重要的区别。
如果您实际上使用的是过时的8.4版本,请转到8.4的旧手册。您知道8.4已在2014年达到停产,并且不再受支持吗?考虑升级到当前版本。
在Postgres 9.1或更高版本中,您也宁愿使用而 不是ident
。
解决方法
如果我说Postgres不接受连接,-h localhost
但是如果我说它可以工作-h 127.0.0.1
[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=#
我的 /var/lib/pgsql/data/pg_hba.conf
# 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服务failed
将启动:
host all all localhost ident
host all all localhost trust
那里怎么了?
更新
我的/etc/hosts
档案:
[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