当我尝试打开 psql
使用此命令:
psql -U postgres
我收到此错误:psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"
但是当我使用它时它连接成功:sudo -u postgres psql
有人可以解释发生了什么以及如何诊断/解决这个问题吗?我的 pg_hba.conf
包含以下内容:
# Database administrative login by Unix domain socket
local all postgres peer
# 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 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
最佳答案
Peer authentication表示只有当数据库用户名与操作系统用户名相同时才允许连接。
所以如果你运行 psql -U postgres
作为操作系统用户root
或 jimmy
,它不会工作。
您可以指定 mapping pg_ident.conf
中的操作系统用户和数据库用户之间的.
关于postgresql - psql : error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres" (Ubuntu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69676009/