O'Reilly logo

PostgreSQL 9 Administration Cookbook by Hannu Krosing, Simon Riggs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Temporarily preventing a user from connecting

Sometimes you need to temporarily revoke user's connection rights without actually deleting the user or changing the user's password.

This recipe presents ways to do 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...

To temporarily prevent the user from logging in, run the following:

pguser=# alter user bob nologin;
ALTER ROLE

To let the user connect again, run the following:

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 to log in. It does not kick out already connected users.

Limiting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required