How to change PostgreSQL password

Timothy Macharia
2 min readJun 13, 2020
Photo by Caspar Camille Rubin on Unsplash

Incase you might have forgotten your PSQL master password, here is a way to go about changing it if you are on Windows.

Open pg_hba.conf file which is located in the ‘C:\Program Files\PostgreSQL\12\data’ folder. The plan is to change connection method from md5 to peer to allow local connections at first. Make sure you edit the file first.

After you’ve changed from md5 to peer, open up a command prompt window so that you can now change the default password.

After you open cmd, type ‘psql postgres postgres’. If psql is not identified as a known command follow the necessary steps in adding the ‘C:\Program Files\PostgreSQL\12\bin’ bin folder to your environment variables.

If your ‘psql postgres postgres’ command run successfully, you will get the prompt postgres-#. Type \password to be prompted to enter a new password. Type your new password, re-enter it again and that’s it. Type \q to exit the isolated environment.

You can now re-edit the changes we made to pg_hba.conf back to its original state.

--

--