如果不使用 -h 选项,我可以使用 psql 登录,但使用 -h 失败(localhost 和 127.0.0.1 都不起作用)。不知道哪里出了问题 :(
信息:postgresql 10,Windows 10 上的 ubuntu 16.04。
这是我的 pg_hba.conf
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.0/24 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
我的控制台日志
(meta--fVnbZtTA) root@Deathwing:/mnt/d/xx.us/meta-# psql -U meta -W
Password for user meta:
psql (10.2 (Ubuntu 10.2-1.pgdg16.04+1))
Type "help" for help.
meta=> \q
(meta--fVnbZtTA) root@Deathwing:/mnt/d/xx.us/meta-# psql -h 127.0.0.1 -U meta -W
Password for user meta:
psql: FATAL: password authentication failed for user "meta"
(meta--fVnbZtTA) root@Deathwing:/mnt/d/xx.us/meta-# psql -h 127.0.0.1 -U meta
Password for user meta:
psql: FATAL: password authentication failed for user "meta"
答案1
此调用:
psql -h 127.0.0.1 -U meta
应该与 pg_hba.conf 中的此行匹配:
host all all 127.0.0.1/32 trust
因为这些行是按照文件的顺序进行测试的,并且它在第一个匹配处停止(匹配项为TYPE+DATABASE+USERNAME+[CIDR unless TYPE=local]
,并且该组合是上述调用的第一个匹配项。
trust
意味着服务器不会要求输入任何密码,但根据您的问题,实际发生的情况是要求输入密码,因此您获得的结果与您的 pg_hba.conf 之间存在矛盾
也许你没有pg_hba.conf
在正确的地方编辑。从版本 10 开始,postgresql 有一个反映文件内容的视图,请参阅
https://www.postgresql.org/docs/10/static/view-pg-hba-file-rules.html
此视图有助于检查身份验证配置文件中的计划更改是否有效,或诊断以前的故障。请注意,此视图报告文件的当前内容,而不是服务器上次加载的内容。
您可以检查一下select * from pg_hba_file_rules order by line_number;
内容是否符合您的预期。
另一个 SQL 命令也show hba_file
将报告服务器在哪里找到该文件。
您还需要阅读服务器日志以获取有关身份验证失败或重新加载 pg_hba.conf 文件失败或成功的更多详细信息。
/var/log/postgresql
在 Ubuntu 上,除非另有配置,否则服务器日志位于postgresql.conf