After the initial installation, one might forget to set the password after running the initial script to setup the database. After a while, naturally, we all forget the password. Below are the steps to reset the password for user name "postgres" :
1. In pg_hba.conf, insert or change the below line.
from :
local all postgres
to
local all postgres trust sameuser
2. Restart PostgreSQL services in order for Step 1 changes to take effect :
3. Login to PostgreSQL on the local machine with the user name "postgres" to change the password :
e.g.
psql -U postgres
4. At the "postgres=#" prompt, change the user name "postgres" password :
e.g.
ALTER USER postgres with password 'secure-password';
5. Quit PostgreSQL interactive session by executing "\q", to exit
6. Alter the configuration (what we did in Step 1) to disable password-less login from local machine to PostgreSQL by changing the word "trust" to "md5" in pg_hba.conf.
e.g.
from:
local all postgres trust sameuser
to:
local all postgres md5 sameuser
7. Restart PostgreSQL to make Step 6 changes take effect by repeating Step 2.
8. Re-login to PostgreSQL using the new password by :
psql -U postgres
Voilla !!!

5 comments:
so late still post ar. so hardworking la. hehe
In Steps 2 and 7, for the pg_hba.conf to take effect, you can just use the comman 'reload'. Instead of restarting the Postgres server, it just signals the server to re-read the config files.
It does not work for me.... if I modify the line, server does not start. If I remove "sameuser" part, server start but when using psql -U postgres, password is requested.
I have postgreSQL 9.1
Regards,
Jaime
I have 9.1, and I tried replacing 'md5 sameuser' with 'peer' and it worked.
I also have 9.1. It worked after I replaced 'md5 sameuser' with 'peer'
Post a Comment