PostgreSQL: How to change the password of the user


This article will teach you to change the password of the user in PostgreSQL. To change the password, we use the ALTER ROLE, its uses are described below.

Change the password using the ALTER ROLE.

Syntax:


ALTER ROLE <username> WITH PASSWORD <new_password>


1-  <username>, specify the username for which you want to change the password
2-  <new_password>, here you will put the new password wrapped within a single quote.

The following example will clear you the above statements


ALTER ROLE admin WITH PASSWORD 'Singh@123'


Set the password valid until a date and time


If you want the password should be valid until a particular date time, then you can use the VALID UNTIL clause. The syntax is given below.


ALTER ROLE <username> WITH PASSWORD <new_password> VALID UNTIL <timestamp>;


For example, see the below statements.


ALTER ROLE admin WITH PASSWORD 'Singh@123' VALID UNTIL 'December 31, 2022'


If you want to verify the result then run the following command.


postgres=# \du admin;


Change Password in postgresql
Result of change password

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...