PostgreSQL OperationalError in Django

One of the common exceptions I came across while using PostgreSQL with Django is OperationalError. The error description appears as follow:

  • FATAL: Ident authentication failed for user “username”

The reason for this error according to my findings is you may have given ‘ident’ authentication for all local users. Ident authentication is one of the methods used by PostgreSQL to authenticate the user. The ident authentication method works by obtaining the client’s operating system user name, then determining the allowed database user names using a map file that lists the permitted corresponding pairs of names(courtesy-PostgreSQL). You may have created the user, who can access the database with full power, with a password. And this password is generally hashed by md5.
By default all the local access are set to ident authentication in PostgreSQL. You can find the details in the file ‘pg_hba.conf’.

Solution

First, locate the ‘pg_hba.conf’ file in your linux machine. You can use the command:

  • locate pg_hba.conf

In my system it was located in ‘/etc/postgresql/8.4/main/’ folder. For you it may be different according to the directory in which you installed PostgreSQL.
Now open the file(pg_hba.conf) in edit mode. You will find a line similar to the following:

  • # “local” is for Unix domain socket connections only
  • local all all ident

You have to change the line to:

  • local all all md5

Restart PostgreSQL:

  • /etc/init.d/postgresql restart

Now the exception should vanish.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on March 16, 2012, in Django and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: