To replace a forgotten postgres password with pgAdmin 4:

1.  Make a backup copy of your pg_hba.conf file. The default location is C:\ProgramData\Spire\PostgreSQL\10\pg_hba.conf


2.  Right-click Notepad in the Start Menu and click "Run as administrator".  Open the original pg_hba.conf file. 


3.  Add these 2 lines to the top of the file and save it.  Please make sure the file name and extension don't change.


host all all trust

host all all ::1/128 trust

4.  Launch pgAdmin 4 then right-click the "Servers" node and click "Create -> Server..." to create a new temporary server entry.  Provide a name for your new server on the "General" tab in the "Name" field.


5.  Go to the "Connection" tab.  

  • Enter "localhost" for the "Host" field.
  • Make sure the "Username" field specifies "postgres".
  • Leave the "Password" field blank.  
  • Press "Save" when you're ready.

6.  Expand your new server entry.

  • Expand the "Databases" node.
  • Right-click the postgres database.
  • Click "Query Tool".


7.  Enter the following SQL command into the query editor:

    ALTER USER postgres with password 'your_password_here'; 


  • Replace your_password_here with a password of your choice.
  • Press F5 when you're ready to run the query.

8.  Open the original pg_hba.conf file using a text editor that was started with administrator rights.  Remove the 2 lines at the top of the pg_hba.conf file (that were added in step 3) and save the file.  Ensure the file name and extension don't change.


Note:  If you cannot save changes to the file even if you run the text editor as administrator, you can copy the original file to a secondary backup file and delete the original file.  Then, edit the new copy of the file, make the changes, and use the save-as feature to save it back to the original filename.


9.  Existing server entries in the pgAdmin 4 interface will no longer work since their saved password is wrong.  Add a new server entry with the new postgres password you created in step 7.