In this video I have shown how to reset the forgotten password of PostgreSQL on windows 10 PC.
1. First locate the pg_hba.conf file inside the installation directory of PostgreSQL. In this example the file is located in ‘C:\Program Files\PostgreSQL\12\bin’.
2. Open the file in notepad and comment the below lines by putting # at the beginning.
3. Screenshot after commenting this lines is shown below.
4. Now paste the below 2 line of codes to the file at the bottom and save the file.
host all all 127.0.0.1/32 trust host all all ::1/128 trust
5. Screenshot after adding the above code is shown below.
6. Now restart the postgreSQL service from windows services. After opening the services window. Just right click on postgres service and click on restart.
7. Now open command prompt and login in postgreSQL as shown below.
Use the below command to login from Command Prompt.
psql -U postgres -h localhost
8. After successful login, Execute the below command to reset the password into the desired one.
ALTER USER <user> WITH PASSWORD '<password>';
eg : ALTER USER postgres WITH PASSWORD 'Pgsq1p@ssword';
Now the password should have changed to the new one you have given.
9. Once the password is changed. Revert the changes you have done in the steps 3 and 4.