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          trust
host    all         all         ::1/128               trust

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

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

Though, I can login as by psql -U postgres

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


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?

  • 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, 2011 at 20:19

1 Answer 1


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

sudo passwd postgres


su - postgres
psql -U postgres template1 -c alter user postgres with password 'newpassword';
  • Don't forget to tighten up your pg_hba.conf when you are done too. May 15, 2011 at 20:12
  • 1
    the psql needed quotes for me: psql -U postgres template1 -c "alter user postgres with password 'newpassword'"
    – hultqvist
    Dec 3, 2012 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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