Quickzi: How To Change PostgreSQL Root Password

Here is how to change the PostgreSQL root password from the Linux command line. Replace “root” with any user name to change any password. It is important to note that PostgreSQL does not have an actual “root” user name. The “postgres” user is the super-user for PostgreSQL.

# su postgres
# psql -d template1

You can replace “postgres” with any user name.

4 thoughts on “Quickzi: How To Change PostgreSQL Root Password

  1. This is not the cpmplete picture…. It will only work from the machine where Postgres is installed, and that too only if the pg_hba.conf is configured to ‘trust’ user from the localhost (

  2. I need to find that superuser password for reset on my machine, but I am not a linux user.

    Is there a way I could do it within windows, or by command line?


    ps any explanation should be for a newbie

  3. This solution works, but is not very secure, as the password can appear in psql command history, postmaster log, is visible on the screen and is sent cleartext over the network if you use psql with -h option from a remote computer and no SSL connection.

    As psql’s man page says it has a built-in \password command to address those issues: gives a hidden prompt with confirmation and encrypts the password before sending it to the postmaster:

    # su postgres -c psql
    postgres=# \password
    Enter password :
    Confirm password :

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>