Thursday, March 27, 2014

To reset the Password of the postgres user in PostgreSQL.

Find out the file pg_hba.conf and change the authentication mode to trust so that when switching to that user, it doesn't ask for password.

The file will be mostly at following place in concerned distros

Centos /var/lib/pgsql/data/pg_hba.conf
Ubuntu /etc/postgresql/9.1/main directory

The file will be have a line like below.
# Database administrative login by Unix domain socket
local all postgres peer

change it like

# Database administrative login by Unix domain socket
local all postgres trust

Once its done while switching password will not be prompted.
Once you are inside change the password using following command.

psql -U postgres
ALTER USER postgres with password 'secure-password';

re-modify the pg_hba.conf to the older state and reload the service .

No comments:

Post a Comment