To create a user in PostgreSQL whose password is valid until a specified time, use CREATE USER query with VALID UNTIL option.

The syntax is shown below.

CREATE USER username WITH [otheroptions] PASSWORD 'password' VALID UNTIL 'absolutedate';

where username is the name of user, otheroptions are like CREATEDB, CREATEROLE, etc., and absolutedate is the absolute date. password should be replaced with password you would like set up for the user.

Example 1 – Create user with Password valid until specific date

In this example, we will create a user with name lini whose password is valid until 2020-11-08 in PostgreSQL database.

CREATE USER lini WITH PASSWORD 'P8Ssi6@86s$sasdimrg' VALID UNTIL '2020-11-08';

Run this query in Query Tool.

PostgreSQL - Create User with Password

Now, if you list users using \du command in psql shell, we see that the user is created with password until the date specified in query.

ADVERTISEMENT
PostgreSQL - Create User with Password VALID UNTIL specific date

Conclusion

In this PostgreSQL Tutorial, we have created a user with password with validity specified in the query.