In this article, I wanna post tutorial about how to reset postgres password in RHEL. If you are using Windows, you can find tutorial here.

Postgres is superuser/root on database PostgreSQL. Unlike MySQL, in PostgreSQL there is no root user. We use postgres as root user. But what if we forget about this postgres password? There is some way to change postgres password without knowing its password.

I have face this problem when I using RHEL. So in this article, I will show you how to do it in RHEL. First, you must edit file pg_hba.conf. Find the actual configuration inside that file, there is 5 column there: TYPE, DATABASE, USER, ADDRESS, METHOD.

In column METHOD, change all method to trust. Then restart service PostgreSQL.

Now, you can login without using postgres without password. After that, change postgres password using command:
ALTER USER postgres with password 'secure-password';

Change back all method in pg_hba.conf to md5. Then restart PostgreSQL service. Now postgres user can login using new password. :)