Reset PostgreSQL database password

Backup this file:
cp /var/lib/pgsql/data/{pg_hba.conf,pg_hba.conf.backup}
Overwrite all content with super user mode:
echo local  all   all   trust> /var/lib/pgsql/data/pg_hba.conf
Check if there really is some content:
cat /var/lib/pgsql/data/pg_hba.conf
Restart service:
service postgresql restart
Enter database mode:
psql -U postgres
Set new password to user postgres:
ALTER USER postgres with password 'rand0m';
Exit database mode:
\q
Restore configuration file:
cp /var/lib/pgsql/data/{pg_hba.conf.backup,pg_hba.conf}
Check if there is some old content:
grep -v "^$\|#" /var/lib/pgsql/data/pg_hba.conf
Restart service:
service postgresql restart

No comments: