How to Solve the FATAL: Password Authentication Failed for User "Postgres" Error

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:

img

To rectify the stated error, first, open the Notepad from the computer by clicking on the “Run as administrator” button:

img

Expand the “File” menu from the notepad and click on the “Open” button or press Ctrl+O from the keyboard:

img

Head into the “data” folder from the “PostgreSQL” directory to select the “pg_hba.conf” file and click on the “Open” button:

img

Scroll down to the bottom of the file to copy the last section of the file and store it on the local system:

img

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:

img

Open the “Run” dialog box from the local system:

img

Type the “services.msc” and click on the “OK” button:

img

Locate the “PostgreSQL” file from the list of all the services to click on it and then click on the “restart” button:

img

Restart the PostgreSQL client and it will allow the user to access the Postgres database to open the “Query Tool”:

img

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';
img

Head back to the “pg_hba.conf” file from the “PostgreSQL” directory to select and change the “trust” with the “scram-sha-256” keyword:

img

Open the “Run” application one more time from the system:

img

Head into the “services.msc” page by clicking on the “OK” button:

img

Select the PostgreSQL file and click on the “Restart” button:

img

Open the PostgreSQL client to use the password and click on the “OK” button:

img

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.