This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing few steps for recovering the forgot password of postgres user (admin user) of PostgreSQL.
Yesterday, I was checking few forums of PostgreSQL and found that few DBAs forgot their password after installation of PostgreSQL.
The postgres user is a superuser of PostgreSQL, and it is a default user also. While installing PostgreSQL, you have to set the password of postgres user, and if you forget the password, you can’t do any operation like create first DB or create first DB User.
How to recover forgotten password of PostgreSQL?
Edit pg_hba.conf file:
Change below line for MD5 to TRUST
1 |
host all postgres 127.0.0.1/32 trust |
Restart the PostgreSQL Server:
1 |
sudo /etc/init.d/postgresql restart |
Connect the PostgreSQL:
1 |
psql -h localhost -U postgres |
Change the password of postgres user:
1 |
ALTER USER postgres with password 'new_password'; |
Last, rollback the change in pg_hba.conf file and restart the PostgreSQL Server: