postgresql - psql : error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres" (Ubuntu)

标签 postgresql ubuntu

当我尝试打开 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作为操作系统用户rootjimmy ,它不会工作。
您可以指定 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/

相关文章:

regex - 如何在从 Postgresql 中的字符串中删除停用词后删除引号和数字

sql - 在未嵌套的 jsonb 列上优化 GROUP BY + COUNT DISTINCT

ubuntu - gcc/Ubuntu : Finding the disk path to the library used at linkage

php - imagettftext 无法打开字体文件

sql - 如何将 postgres 函数的结果保存到变量中?

postgresql - Postgres读写外部文件

ruby - Postgres段错误 ruby gem

networking - 读取其他从属的map任务的mapoutput时出错,应该是运行Hadoop集群的ubuntu的etc/hosts文件的实际内容是什么

python - 使用pyenv在Python的两个系统版本之间切换

linux - Sed 不能处理特殊字符