use the ALTER USER command to modify the user's password, password expiration, lock, unlock
(1) Modify the user's password and change the user's password to a new password
highgo= #create user test with password ' test ';
Createrole
highgo= #select usename,passwd from Pg_shadow;
Usename | passwd
---------+-------------------------------------
Highgo | md5614aeb636ab143b790547ce463ec1741
A | md5039af99d1e9a4b194e0eb800a6f8d018
B | Md583aeaa4e529325e234e9c5c2e01e6c08
Test | Md505a671c66aefea124cc08b76ea6d30bb
(4rows)
highgo= #ALTER USER test with password ' testnew ';
Alterrole
highgo= #select usename,passwd from Pg_shadow;
Usename | passwd
---------+-------------------------------------
Highgo | md5614aeb636ab143b790547ce463ec1741
A | md5039af99d1e9a4b194e0eb800a6f8d018
B | Md583aeaa4e529325e234e9c5c2e01e6c08
Test | md57c56448e70f764f1ca97ceae33823c9b
(4rows)
(2) Set the user password expiration by setting the user to expire, so that the user must change the password at the next logon.
highgo=# select Usename,valuntil from Pg_shadow;
Usename | Valuntil
---------+----------
Highgo |
A |
B |
Test |
(4rows)
highgo= #alter user test with valid until ' 2017-4-4 12:48:00 ';
Alterrole
highgo= #select usename,valuntil from Pg_shadow;
Usename | Valuntil
---------+------------------------
Highgo |
A |
B |
Test | 2017-04-04 12:48:00+08
(4rows)
Remote use of test to connect to the database will fail at this time.
(3) Lock the user, after the user locked, the locked user is not able to log in to the system again.
highgo= #ALTER USER Test nologin;
Alterrole
Highgo=#\c Highgo Test
Fatal error: The role ' Test ' is not allowed to log on
Fatal error: The role ' Test ' is not allowed to log on
Previousconnection kept
highgo=#
(4) Unlock the user, unlock the user's lock state.
highgo= #ALTER USER Test login;
Alterrole
Highgo=#\c Highgo Test
Youare now connected to database "Highgo" as user "test". Highgo=>