如何配置 PostgreSQL 以允许默认的 postgres 用户从本地主机无密码登录?
还有几个类似的问题,比如this和 this ,但是修改 pg_hba.conf
的建议对我都没有用。但是,根据我对 pg_hba.conf
规则的理解,我应该能够使用 peer
或 trust
选项来完成此操作。
我正在尝试运行如下命令:
sudo psql --user=postgres --no-password --command="blah;" -h 127.0.0.1
如果我在我的 pg_hba.conf
中尝试这一行:
local all postgres trust
我的命令因错误而失败:
psql: FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL on
FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL off
如果我尝试这一行:
local all postgres peer
我的命令因同样的错误而失败。
我该如何解决这个问题?
最佳答案
当您指定 -h 127.0.0.1
时,不是“本地”连接 - 它是主机(=基于 TCP)连接。因此,以 local
开头的行将不匹配此类连接。
要使该条目有效,请不为psql
指定主机名或端口,然后它将通过命名管道使用“本地”连接。
或者,您可以使用 host
local
,然后将 127.0.0.1
作为(客户端)IP 地址添加到“信任”。
关于postgresql - 如何允许在本地连接上没有密码提示的情况下登录 postgres?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46736894/