【发布时间】: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