Temporarily preventing a user from connecting
Sometimes, you need to temporarily revoke a user’s connection rights without deleting the user or changing their password. This recipe presents ways of doing this.
Getting ready
To modify other users, you must either be a superuser or have the CREATEROLE
privilege (in the latter case, only non-superuser roles can be altered).
How to do it…
Follow these steps to temporarily prevent and reissue the login capability of a user:
- To temporarily prevent the user from logging in, run this command:
pguser=# alter user bob nologin; ALTER ROLE
- To let the user connect again, run the following command:
pguser=# alter user bob login; ALTER ROLE
How it works…
This sets a flag in the system catalog, telling PostgreSQL not to let the user log in. It does not kick out already connected users.
There’s more…
Here are some additional remarks...