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

时间:2021-04-02 06:04:29

标签: python postgresql ubuntu

我已经安装了 PostgreSQL 并创建了一个具有超级用户权限的用户“userrole”。也可以通过python代码连接。

export const magentoOptions = {
  url: 'http://10.0.2.2/magento241/', // make sure you have trail slash in the end
  home_cms_block_id: '35',
  store: 'default', // store code // Stores > All Stores > Store View > Code
  authentication: {
    integration: {
      access_token: '0fy0b0sa497uadi3q6177tmin4rc0z4b',
    },
  },
  reviewEnabled: false, // set true ONLY if you install https://github.com/troublediehard/mma-customapi on the magento backend
};

这是我的输出:

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()

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

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

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

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

2 个答案:

答案 0 :(得分:1)

您最近的 psql 尝试尝试通过 Unix 套接字进行连接,该套接字(显然,基于错误消息)配置为用户对等身份验证。

要使用密码,您需要通过 TCP 连接,就像您的 Python 所做的那样:

psql -U userrole -h 127.0.0.1

此外,sudo 对基于密码的身份验证无用,所以我将其删除

答案 1 :(得分:0)

userrole 是 SQL 用户。它不是 Linux 用户。这两个用户列表是完全独立的。

相关问题