Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I forgot passwords for postgresql root user: postgres

So I changed pg_hba.conf to have trust method for everything (this is my local dev box)

local   all         postgres                          trust
local   all         all                               trust
host    all         all         127.0.0.1/32          trust
host    all         all         ::1/128               trust

after restarting the service it is still asking me for password.

@omnipresent:~$ su - postgres
Password: 
su: Authentication failure

Though, I can login as by psql -U postgres

@omnipresent:~$ psql -U postgres
psql (8.4.8)
Type "help" for help.

postgres=# 

the mess I am in, at this point I'd just like to make a new role for postgresql and make that user an admin.

How can I do that being in this situation?

share|improve this question
    
The key here is that system accounts (what you are logging into with su) and postgresql accounts (what you are logging into with psql) are entirely different sets of accounts. Use Antonius's advice to change the system password for the "postgres" system user. –  DerfK May 15 '11 at 20:19

1 Answer 1

up vote 3 down vote accepted

To change the password of any linux user, including the Postgres root:

sudo passwd postgres

Then:

su - postgres
psql -U postgres template1 -c alter user postgres with password 'newpassword';
share|improve this answer
    
Don't forget to tighten up your pg_hba.conf when you are done too. –  Antonius Bloch May 15 '11 at 20:12
    
the psql needed quotes for me: psql -U postgres template1 -c "alter user postgres with password 'newpassword'" –  phq Dec 3 '12 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.