1) edit pg_hba.conf to
change all local connections from md5 to trust.
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
2) restart PostgreSQL service
3) connect to PosgreSQL using any tool:
psql -U postgres
4) change password
postgres=# ALTER USER postgres WITH PASSWORD 'new_password';
5) restore
pg_hba.conf and restart PostgreSQL
service