Change the authentication method in the PostgreSQL configuration file pg_hba.conf from md5 to trust and reload the configuration.
#Approach A (Bitnami installations using system packages):
sudo sed -ibak 's/^\([^#]*\)md5/\1trust/g' /opt/bitnami/postgresql/conf/pg_hba.conf
sudo -u postgres pg_ctl reload
#Approach B (Self-contained Bitnami installations):
sudo sed -ibak 's/^\([^#]*\)md5/\1trust/g' /opt/bitnami/postgresql/data/pg_hba.conf
sudo -u postgres pg_ctl reload
Connect to the PostgreSQL database and set the password to a new value:
psql -U postgres
postgres=# alter user postgres with password 'NEW_PASSWORD';
postgresl=# \q
Finally, change the authentication method back to md5 and reload the old PostgreSQL configuration:
#Approach A (Bitnami installations using system packages):
sudo sed -ibak 's/^\([^#]*\)trust/\1md5/g' /opt/bitnami/postgresql/conf/pg_hba.conf
sudo -u postgres pg_ctl reload
#Approach B (Self-contained Bitnami installations):
sudo sed -ibak 's/^\([^#]*\)trust/\1md5/g' /opt/bitnami/postgresql/data/pg_hba.conf
sudo -u postgres pg_ctl reload