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 !!!
10 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'
It doesn't work with
local all postgres trust sameuser
But it worked with
local all postgres trust
Thanks for the tip
Thanks for the info.
Note that with Postgresql 9.2 "trust sameuser" is not accepted anymore, instead use only "trust".
Thanks this post was still helpful in postgres 9.4. Just you dont have to use "sameuser".
[x] pg_hba.conf (from data folder)
host all postgres 127.0.0.1/32 trust
#host all all 127.0.0.1/32 md5
[x]cmd prompt
psql -U postgres -h 127.0.0.1
ALTER USER postgres with password 'admin';
Note:dont forget ";" to alter password
I tried like su - postgres but password is not matched.
Unfortunately i forgot my password..
Now i need to recover that..
Pls help me.....
Post a Comment