简体   繁体   English

Postgresql psql:错误:致命:用户“userrole”的对等身份验证失败

[英]Postgresql psql: error: FATAL: Peer authentication failed for user "userrole"

I have installed PostgreSQL and created a user 'userrole' with superuser privileges.我已经安装了 PostgreSQL 并创建了一个具有超级用户权限的用户“userrole”。 Also able to connect through python code.也可以通过 python 代码连接。

import psycopg2
conn = psycopg2.connect(
   database="postgres", user="userrole", password="userroot", host='127.0.0.1', port= '5432'
)
cursor = conn.cursor()
cursor.execute("select version()")
data = cursor.fetchone()
print("Connection established to: ",data)
conn.close()

This is my output:这是我的 output:

Connection established to:  ('PostgreSQL 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit',)

Process finished with exit code 0

The issue I'm facing is through CLI is cannot connect to this user:我面临的问题是通过 CLI 无法连接到该用户:

(venv) resh@project:~/PycharmProjects/utilities$ sudo su -l userrole
[sudo] password for resh: 
su: user userrole does not exist

Sorry, I am new to ubuntu, now I have changed the command and still getting an issue:抱歉,我是 ubuntu 的新手,现在我更改了命令但仍然遇到问题:

(venv) resh@project:~/PycharmProjects/utilities$ sudo psql -U userrole
[sudo] password for resh: 
psql: error: FATAL:  Peer authentication failed for user "userrole"

Your latest psql attempt is trying to connect over the Unix socket, which is (apparently, based on error message) configured to user peer authentication.您最近的 psql 尝试尝试通过 Unix 套接字进行连接,该套接字(显然,基于错误消息)配置为用户对等身份验证。

To use the password, you need to connect over TCP, like your python is doing:要使用密码,您需要通过 TCP 进行连接,就像您的 python 所做的那样:

psql -U userrole -h 127.0.0.1

Also, the sudo is useless for password-based authentication, so I removed it另外,sudo 对于基于密码的身份验证没有用,所以我删除了它

userrole is an SQL user. userrole是 SQL 用户。 It is not a Linux user.它不是 Linux 用户。 The two user lists are completely separate.这两个用户列表是完全分开的。

I had the same problem and fixed it by using following command in Ubuntu:我遇到了同样的问题,并在 Ubuntu 中使用以下命令修复了它:

psql -d database -U username -h 127.0.0.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PostgreSQL - 用户“postgres”的对等身份验证失败 - PostgreSQL - Peer authentication failed for user “postgres” postgresql:致命:用户“道格拉斯”的密码验证失败 - postgresql: FATAL: password authentication failed for user "douglas" Django 错误:django.db.utils.OperationalError:致命:用户对等身份验证失败 - Django error: django.db.utils.OperationalError: FATAL: Peer authentication failed for user 用户“odoo”的对等身份验证失败 - Peer authentication failed for user “odoo” django.db.utils.OperationalError:严重:用户“ deadlylaid”的对等身份验证失败 - django.db.utils.OperationalError: FATAL: Peer authentication failed for user “deadlylaid” Django设置:psycopg2.OperationalError:致命:用户“indivo”的对等身份验证失败 - Django setting : psycopg2.OperationalError: FATAL: Peer authentication failed for user “indivo” 严重:用户的密码身份验证失败 - FATAL: password authentication failed for user Postgresql - 用户密码验证失败 - Postgresql - password authentication failed for user 对等身份验证失败,docker 和 postgreSQL / Mac OS / Python - Peer authentication failed with docker and postgreSQL / Mac OS / Python psycopg2.OperationalError:严重:用户的密码身份验证失败,但该用户不在该计算机上 - psycopg2.OperationalError: FATAL: password authentication failed for user but the user is not on that machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM