Postgresql – forgot passwords for postgresql users. how to login

postgresqlubuntu-11.04

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?

Best Answer

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';