psycopg2.OperationalError: FATAL: Peer authentication failed for user “username”
I was setting up a friend’s project on my Ubuntu 12.04 laptop last night and ran into this database connection problem when I tried to ran his Django application.
There are actually 2 solutions to this problem:
In your settings.py file, in the database settings, set the ‘HOST’ to ‘localhost’ instead of an empty string.
Modify the /etc/postgresql/9.1/main/pg_hba.conf file and change the authentication setting of local from peer to md5.
Peer authentication basically uses the currently logged in user’s credentials to authenticate, which in my case doesn’t have access to the database.
MD5 authentication is password-based authentication and will use the username and password you specified in the settings file.