PostgreSQL is an open-source database management system that allows the user to create relational databases using different CLI or GUI applications. The user will need to set the credentials for the servers which will be required while accessing the PostgreSQL server at any moment. Additionally, it enables the user to alter the passwords and credentials if the user has lost them.
This guide will explain how to solve the password authentication error for the user in PostgreSQL.
How to Solve the FATAL: Password Authentication Failed for User Postgres Error?
This error occurs in the PostgreSQL client application when the user provides the wrong password while connecting to the server:
To rectify the stated error, first, open the Notepad from the computer by clicking on the “Run as administrator” button:
Expand the “File” menu from the notepad and click on the “Open” button or press Ctrl+O from the keyboard:
Head into the “data” folder from the “PostgreSQL” directory to select the “pg_hba.conf” file and click on the “Open” button:
Scroll down to the bottom of the file to copy the last section of the file and store it on the local system:
After that, change the “scram-sha-256” with the “trust” keyword in the “METHOD” column, and click on the “Save” button from the “File” menu:
Open the “Run” dialog box from the local system:
Type the “services.msc” and click on the “OK” button:
Locate the “PostgreSQL” file from the list of all the services to click on it and then click on the “restart” button:
Restart the PostgreSQL client and it will allow the user to access the Postgres database to open the “Query Tool”:
Run the following query to change the password of the “postgres” user and then access the server using the newly provided password:
ALTER USER postgres WITH PASSWORD 'postgres';
Head back to the “pg_hba.conf” file from the “PostgreSQL” directory to select and change the “trust” with the “scram-sha-256” keyword:
Open the “Run” application one more time from the system:
Head into the “services.msc” page by clicking on the “OK” button:
Select the PostgreSQL file and click on the “Restart” button:
Open the PostgreSQL client to use the password and click on the “OK” button:
That’s all about solving the password authentication error while connecting to the server.
Conclusion
To solve the Fatal: password authentication failed for the user “postgres” error while connecting to the server, simply open the “pg_hba.conf” file. Change the values in the method column from the last section and then restart the PostgreSQL application from the “services.msc” application. Open the PostgreSQL client and change the password to log in to the server. This guide has explained the process of solving the password authentication failed error while connecting to the PostgreSQL server.