Postgres uses the ALTER USER command to modify the user's password, password expiration, lock, unlock

Source: Internet
Author: User
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=>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.