How to recover the password for postgres user (admin user) of PostgreSQL
This article explains the steps to recover the password for postgres user (admin user) of PostgreSQL.
Step1: Login to the server via ssh as root.
Step2: Update the following line in pg_hba.conf file.
host all postgres 127.0.0.1/32 trust
Step3: Restart PostgreSQL service.
#systemctl restart postgresql
Step4: Login to the PostgreSQL shell.
#psql -h localhost -U postgres
Step5: Modify the password for postgres user.
>ALTER USER postgres with password 'new-password';
Where new password need to be replaced with the required value.
Step6: Revert the changed in pg_hba.conf file.
host all postgres 127.0.0.1/32 md5
Step7: Restart PostgreSQL service.
#systemctl restart postgresql
That's all…