小编Res*_*mar的帖子

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

我已经安装了 PostgreSQL 并创建了一个具有超级用户权限的用户“userrole”。也可以通过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()
Run Code Online (Sandbox Code Playgroud)

这是我的输出:

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
Run Code Online (Sandbox Code Playgroud)

我面临的问题是通过 CLI 无法连接到该用户:

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

抱歉,我是 ubuntu 新手,现在我更改了命令,但仍然遇到问题:

(venv) resh@project:~/PycharmProjects/utilities$ sudo psql -U userrole
[sudo] …
Run Code Online (Sandbox Code Playgroud)

python postgresql ubuntu

5
推荐指数
1
解决办法
9490
查看次数

标签 统计

postgresql ×1

python ×1

ubuntu ×1