【问题标题】:postgresql ident authentication failed for user different than dbuser与 dbuser 不同的用户的 postgresql ident 身份验证失败
【发布时间】:2014-07-17 22:16:21
【问题描述】:

我在 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 上的完整权限。

【问题讨论】:

  • 我认为下面的答案很好地回答了这个问题,因为我设法通过su postgres 解决了这个问题并且问题解决了。

标签: python postgresql centos


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-09
    • 2020-11-30
    • 2015-06-18
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 2013-07-23
    相关资源
    最近更新 更多