How can I change a PostgreSQL user password?

Created by solaimuruganvLinked to 86.9m issues across 85 teams

tl;dr

Step 1 - log in to the PostgreSQL database without a password by using the following command:

sudo -u user_name psql db_name

Step 2 - reset the password if you have forgotten it by using the following command:

ALTER USER user_name WITH PASSWORD 'new_password';