While setting up the Odoo environment in your system it is probable that you might encounter “failed: FATAL: Peer authentication failed”, which arrives when you try to login to your PostgreSQL user but authentication fails because by default psql connects over UNIX sockets using peer authentication instead of password authentication.
If you try to access the odoo from your browser your screen might display as follows:
If you check your terminal logs the output will be similar to the image given below:
There could be several reasons for this error to occur such as:
- Incorrect database credentials provided in the configuration (odoo.conf) file
- Inconsistency in ‘pg_hba.conf’
Let’s see how we can update the ‘pg_hba.conf’ file to assign the database user to solve the issue.
Open your terminal and enter the following commands
cd /etc/postgresql
ls
cd 12/main/
sudo gedit pg_hba.conf
Then you can add your information accordingly as follows (you should provide your database user name)
After saving this file you have to restart your postgresql service using the following command:
sudo service postgresql restart.
Now you can access your Odoo database.
If you give md5 instead of trust you have to provide the exact db_password in your ‘odoo.conf‘ file.
- Peer (or trust) means it will trust the authenticity of a UNIX user and hence does not prompt for the password.
- md5 means it will always ask for a password, and validate it after hashing with MD5.
In case the above-mentioned solution didn’t work for you, changing postgres user’s password may solve the problem.
PostgreSQL is provided with a default user named ‘postgres’. For this, we will use this role and change its password. Run the following command to jump into postgreSQL cmd.
sudo -u postgres psql postgres
Enter your root/sudo password. This will take you to the psql cmd which will be prompted.
Here ‘postgres’ is the username you’re currently logged in with. Now run the following command to change the password.
\password postgres
This will prompt you to enter your new password for user ‘postgres’ and then will ask you to confirm it by re-entering it. You’re done with a possible second solution. Go to database.yml file and update the password for ‘postgres’ username according to your new password. Now run the command to create DB.