PostgreSQL: Change a user password
This PostgreSQL tutorial explains how to change a user's password in PostgreSQL with syntax and examples.
Description
The ALTER USER statement is used to change a user's password in the PostgreSQL database.
Syntax
The syntax for changing a password using the ALTER USER statement in PostgreSQL is:
ALTER USER user_name WITH [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'new_password' | VALID UNTIL 'expiration';
Parameters or Arguments
- user_name
- The user whose password you wish to change.
- new_password
- The new password to assign to the user.
- expiration
- The date/time value when the password will expire. If you never want the password to expire, you set expiration to 'infinity'.
Example
Let's look at an example that shows how to use the ALTER USER statement in PostgreSQL to change a password.
For example, if you wanted to update the user named techonthenet with the password fantastic, you would run the following ALTER USER statement in PostgreSQL:
ALTER USER techonthenet WITH PASSWORD 'fantastic';
If you wanted to set the password for the user techonthenet to expire on January 1, 2015, you would use the ALTER USER statement as follows:
ALTER USER techonthenet VALID UNTIL 'Jan 1, 2015';
If you wanted the password for the user techonthenet to never expire, you would use the ALTER USER statement as follows:
ALTER USER techonthenet VALID UNTIL 'infinity';
Advertisements