4

I have postgresql up and running on centos 6.5. The version I'm running is 9.3. Currently I have a python script that uses psycopg2 to insert data into a databse in postgresql called "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. 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.

1
  • 1
    I think the below answer answers this question well because I managed to solve this problem by just su postgres and the problem solved. Commented Jul 12, 2015 at 17:30

1 Answer 1

3

Ident authentication means that database user "foo" is only available from system user "foo".

If you aren't running your python under user account "foo" then it won't work.

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. See documentation for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.