Skip to content

Instantly share code, notes, and snippets.

@Boorj
Last active January 10, 2020 07:41
Show Gist options
  • Save Boorj/443ed7d7af534466b420f56428730b96 to your computer and use it in GitHub Desktop.
Save Boorj/443ed7d7af534466b420f56428730b96 to your computer and use it in GitHub Desktop.
How to reset Postgres password on windows
  1. locate data folder and pg_hba.conf inside, for example C:\Program Files\PostgreSQL\12\data\pg_hba.conf ;

  2. open the file, you'll see:

# 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
# Allow replication connections from localhost, by a user with the
# replication privilege.
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
  1. change top 2 md5 to trust, so it goes:
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
  1. launch terminal as administrator

  2. run command pg_ctl.exe reload -D "C:\Program Files\PostgreSQL\12\data\" (pg_ctl.exe is in C:\Program Files\PostgreSQL\12\bin folder)

  3. now login to postgres psql -U postgres - logging as user postgres. Terminal will show postgres=#

  4. run

alter user postgres with password 'YOUR NEW PASSWORD @#$@#$@#';
  1. on success it will output ALTER ROLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment