简体   繁体   English

对于不同于dbuser的用户,postgresql ident身份验证失败

[英]postgresql ident authentication failed for user different than dbuser

I have postgresql up and running on centos 6.5. 我有postgresql并在centos 6.5上运行。 The version I'm running is 9.3. 我正在运行的版本是9.3。 Currently I have a python script that uses psycopg2 to insert data into a databse in postgresql called "testdb". 目前我有一个python脚本,它使用psycopg2将数据插入postgresql中名为“testdb”的数据库中。 When I try to run it on the server I run into this error: 当我尝试在服务器上运行它时,我遇到了这个错误:

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"

This is my pg_hba.conf file. 这是我的pg_hba.conf文件。 I can not understand whats wrong. 我无法理解什么是错的。

#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

I have given user 'foo' full priveleges on testdb. 我已经在testdb上给了用户'foo'完整的priveleges。

Ident authentication means that database user "foo" is only available from system user "foo". Ident身份验证意味着数据库用户“foo”仅可从系统用户“foo”获得。

If you aren't running your python under user account "foo" then it won't work. 如果你没有在用户帐户“foo”下运行你的python,那么它将无法正常工作。

If you don't know what "ident" authentication is and can't be bothered to read up on it, switch to password, that seems to be what you wanted. 如果您不知道“身份”身份验证是什么,并且无法阅读它,请切换到密码,这似乎是您想要的。

Oh - you can create a .pgpass file containing username+password details too. 哦 - 您也可以创建一个包含用户名+密码详细信息的.pgpass文件。 See documentation for details. 请参阅文档了解详细信

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM