python - 与 dbuser 不同的用户的 postgresql 身份验证失败

标签 python postgresql centos

我在 centos 6.5 上启动并运行了 postgresql。我运行的版本是 9.3。目前我有一个 python 脚本,它使用 psycopg2 将数据插入到 postgresql 中名为“testdb”的数据库中。当我尝试在服务器上运行它时,我遇到了这个错误:

Traceback (most recent call last):
File "collector2.py", line 10, in <module>
con = psycopg2.connect(database='testdb', host = 'localhost', user = 'foo', password = '12345')  
File "/usr/lib64/python2.6/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL:  Ident authentication failed for user "foo"

这是我的 pg_hba.conf 文件。我不明白怎么了。

#TYPE  DATABASE        USER            ADDRESS                 METHOD

local   all             postgres                                peer
# "local" is for Unix domain socket connections only
local   all             all                                     peer
local   all             all                                     ident
local   testdb     foo                              peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

我已授予用户“foo”对 testdb 的完全权限。

最佳答案

身份验证意味着数据库用户“foo”只能从系统用户“foo”获得。

如果您没有在用户帐户“foo”下运行您的 python,那么它将无法工作。

如果您不知道“身份”身份验证是什么,也懒得去阅读它,请切换到密码,这似乎就是您想要的。

哦 - 您也可以创建一个包含用户名+密码详细信息的 .pgpass 文件。有关详细信息,请参阅文档。

关于python - 与 dbuser 不同的用户的 postgresql 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23915877/

相关文章:

python - vim:突出显示Python三引号字符串中的SQL

python - 为什么有些项目没有在 Odoo 中翻译?

python - 如何拆分字符串中的两个项目?

sql - SQL JOIN 查询中的重复条目

openssl - 在centos 7服务器上使用directadmin和letsencrypt安装HTTP版本2

python - VS 代码 'Run Python in Terminal' 播放按钮不工作

postgresql - BIRT 报告 postgreSQL DB 上的异常

postgresql - 设置 : The program 'pg_config' is required but it could not be found

linux - 我怎样才能将linux centos中的树形目录转换为文本文件

php - 升级到 PHP5.6 后,pecl oci8 安装失败