PostgreSQL User Password
Miraculous events happen on my students’ computers almost weekly. For example, one couldn’t remember their student user’s password, which I set by default. How did they change it? They don’t recall.
Assuming you have sudoer authority on a Linux operating system, you can change a PostgreSQL user’s password as follows:
- Assume the root user’s role with the following command:
sudo sh
- As the root user, assume the postgres user’s role with the following command:
su - postgres
- As the postgres user, connect to the PostgreSQL database with the following command:
psql -U postgres
- Assuming the user’s name is student and you want to set the password to a trivial value like student, use the following command:
ALTER USER student WITH ENCRYPTED PASSWORD 'student';
As always, I hope this helps somebody trying to sort out the syntax and workflow.