Lock and Unlock PostgreSQL User

In this article, we are going Lock and Unlock PostgreSQL User. Privileges required to Lock and Unlock PostgreSQL User is ALTER USER.

Steps to Lock and Unlock PostgreSQL User:

1. Lock the user

ALTER USER anil NOLOGIN;

2. Try to connect to the server with locked user.

psql -U anil -d postgres;

Lock and Unlock PostgreSQL User

3. Unlock the user.

ALTER USER anil NLOGIN;

4. Try to connect to the server with unlocked user.

psql -U anil -d postgres;

This is explained in the below video: