SET PASSWORD
Function
Change the user password.
Precautions
- If no user is specified, the password of the current user is changed.
- An initial user can change the password of any user (including its own password). REPLACE does not need to be specified to verify the current password.
- A non-initial user cannot change the password of an initial user.
- The sysadmin user and users with the createrole permission can change the passwords of other users (non-initialization, non-sysadmin, and non-createrole users). REPLACE does not need to be specified to verify the current password.
- When the sysadmin user or a user with the createrole permission changes the password, REPLACE must be specified to verify the current password.
Syntax
SET PASSWORD [FOR user] = password_option [REPLACE 'current_auth_string']
password_option: {
'auth_string'
| PASSWORD('auth_string')
}
Parameter Description
[FOR user]
user supports the following formats:
- user (case insensitive).
- 'user' (case sensitive).
- “user” (case sensitive)
- 'user'@'host' (case sensitive).
- current_user()/current_user.
auth_string
Password to be set.
current_auth_string
Old password.
Examples
--Changes the password of the specified user.
openGauss=# create user user1 with password 'abcd@123';
CREATE ROLE
openGauss=# set password for user1 = 'abcd@124';
ALTER ROLE
--Changes the password of the current user.
openGauss=# set password = 'abcd@123';
ALTER ROLE
openGauss=# set password for current_user = 'abcd@123';
ALTER ROLE
openGauss=# set password for current_user() = 'abcd@123';
ALTER ROLE
Feedback