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’.
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
- /etc/init.d/postgresql restart
Now the exception should vanish.