How to reset the postgres user’s password in Windows

I encountered an issue where all of my databases were owned by the postgres user, but I had no idea what the password was. Here are the steps I took to reset the password for postgres.

This link provided most of the clues for how to fix this problem:

PostgreSQL: Reset root password

1. Open this file:
C:\Program Files\PostgreSQL\9.1\data\pg_hba.conf

2. Change This:
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

To This:
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

The trust keyword will allow someone to login as any user without a password.

3. Run this command to refresh the configuration file:

pg_ctl.exe reload -D “C:\Program Files\PostgreSQL\9.1\data”

4. Login as postgres

5. Run this SQL to change the postgres password:

ALTER USER postgres WITH PASSWORD ‘postgres’;

6. Change pg_hba.conf values from trust back to md5 and refresh the configuration file

This entry was posted in Database. Bookmark the permalink.

Leave a comment