Postgres不允许localhost但可与127.0.0.1一起使用
技术问答
311 人阅读
|
0 人回复
|
2023-09-14
|
如果我说Postgres不接受连接,-h localhost但如果我说它能工作的话-h 127.0.0.1( G @, J; I: I" A
[root@5d9ca0effd7f opensips]# psql -U postgres -h localhost -WPassword for user postgres:psql: FATAL: Ident authentication failed for user "postgres"[root@5d9ca0effd7f opensips]# psql -U postgres -h 127.0.0.1 -WPassword for user postgres:psql (8.4.20)Type "help" for help.postgres=#我的 /var/lib/pgsql/data/pg_hba.conf
2 P' q# I1 E2 D# TYPE DATABASE USER CIDR-ADDRESS METHOD# "local" is for Unix domain socket connections onlylocal all all trustlocal all all ident# IPv4 local connections:host all all .0.0.1/32 trusthost all all .0.0.1/32 ident# IPv6 local connections:host all all ident如果我添加以下行动,则添加以下行动Postgres服务failed将启动:
$ C7 W9 T: W9 L* dhost all all localhost identhost all all localhost trust那里怎么了?/ v7 g: r( S* r1 o! p
更新我的/etc/hosts档案:
8 T1 p: S& f- G[root@5d9ca0effd7f opensips]# cat /etc/hosts172.17.0.2 5d9ca0effd7f127.0.0. localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allrouters
) J( @; a7 d4 Q4 N1 j H 解决方案:
5 X4 P* r/ l9 x& D9 g 在pg_hba.conf中,第 一个匹配
+ @# ` d4 C% }2 C& _2 F# p& c计数。每个文档:7 f: ~( T" ^0 H& p9 h# E# Q/ }
具有匹配的连接类型、客户端地址、要求的数据库和用户名的第一个记录用于身份验证。没有失败或备份:如果选择记录并验证失败,则不考虑后续记录。如果没有记录匹配,则拒绝访问。6 }" t+ q# K0 W# L z! N
请注意 相反的顺序 :& ^ y5 f" | C4 F i
host all all .0.0.1/32 trusthost all all .0.0.1/32 ident但:7 L& a4 P, ^; ^( M1 z* K$ f" {5 g
host all all localhost identhost all all localhost trust保存更改后,请记住- U, E L( t! C5 B- C
重新加载pg_hba.conf。手册:
) { U% s4 \3 q& k5 L- d该pg_hba.conf当主服务器启动时,文件被读取并处理SIGHUP信号。如果您在活动系统上编辑文件,您需要向邮局局长发送信号(使用pg_ctlreload,调用SQL函数pg_reload_conf()或使用kill -HUP),重读文件。, l& @. D4 N9 E6 T0 d: r
如果你真的像你写的那样添加这些行,根本不会有效果。但是,如果你 更换 管线,则存在。
4 o# e- d' V) G% w& p k在第一种情况下,你会得到它trust这是一种开放的身份验证方法。每个文档:$ w) A6 ]) t4 C( V2 A+ [ Q9 {
PostgreSQL任何能够连接到服务器的人都有权使用他们指定的数据库用户名(甚至超级用户名)访问数据库。
. L9 y1 u6 _1 |但在第二种情况下,你会得到它ident必须正确设置身份验证方法才能起作用。
# d# I: T2 ?9 c1 j另外,正如Cas稍后指出的那样,它localhost涵盖了IPv4和IPv6,而127.0.0.1/32仅适用于IPv4。如果使用IPv6.这是一个重要的区别。9 a& B" f1 u0 G2 n* d6 p# M1 l* R
如果你实际上使用过时的8.4版,请转到8.4旧手册。你知道8.2014年停产,不再支持吗?考虑升级到当前版本。3 G& s+ W: N: f8 K
在Postgres 9.在1或更高的版本中,你也宁愿使用 peer 不是ident。 |
|
|
|
|
|