使用ALTER USER命令修改用户的密码、密码过期,锁定,解锁
(1)修改用户的口令,将用户的口令修改为新的密码
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)设置用户口令过期,通过设置用户过期,这样该用户在下次登录的时候就必须要修改密码。
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)
此时远程使用test连接数据库将失败。
(3)锁定用户,将用户锁定之后,被锁定的用户是不能够再次登录到系统中。
highgo=#ALTER USER test nologin;
ALTERROLE
highgo=#\c highgo test
致命错误: 不允许角色”test”进行登录
致命错误: 不允许角色”test”进行登录
Previousconnection kept
highgo=#
(4)解锁用户,解锁用户的锁定状态。
highgo=#ALTER USER test login;
ALTERROLE
highgo=#\c highgo test
Youare now connected to database “highgo” as user “test”.
highgo=>