当我尝试用以下命令打开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
发布于 2022-01-18 00:26:04
您可以使用编辑器以特权编辑.conf文件,在我的例子中,它是nano。
$sudo nano /etc/postgresql/14/main/pg_ident.conf
通过添加以下行来映射用户
# MAPNAME SYSTEM-USERNAME PG-USERNAME
user1 <computer-username> postgres
将<computer-username>
替换为System,这可以使用命令找到。键入您的终端:
$whoami
那就去pg_hba.conf吧
$sudo nano /etc/postgresql/14/main/pg_hba.conf
使用method=peer添加postgre用户,如下所示:
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
这对我有用。
https://stackoverflow.com/questions/69676009
复制相似问题