Tutorial on how to change the password for a postgres user.
This post contains steps to change your password in postgres. It requires that you know your current password. If you’ve lost your password and need to reset it, jump to this section .
Open up a terminal, and run the following command to log into psql:
sudo -u myusername psql
Now that you’re logged ino psql, you can change your password by running the following command:
After you run that command, you’ll get a prompt asking you to enter a new password. Enter your new password and then quit out of psql by running:
After you perform the password change, you’ll want to restart the postgres server. From the terminal, run:
sudo service postgresql restart
That’s it! You’ve successfully changed your postgres password for a particular user.
As a bonus, you did it in a secure way. The password won’t be stored in your terminal history since you did it directly in psql.
If you’ve lost your current password for a user, don’t worry. As long as you have sudo privileges on the machine, you’ll be able to change it.
You’ll need to login to psql without a password. Type the following command in your terminal:
sudo -u your_user_name psql database_name
To reset the forgotten password, run the following command in psql:
ALTER USER your_user_name WITH PASSWORD 'some-new-password';
This will set the password for the
your_user_name user to
Success. You now have reset the password for a postgres user account.
For other Postgres examples: https://www.mikesallese.me/tags/postgres