Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Overview of this book

Table of Contents (19 chapters)
PostgreSQL 9 Administration Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Temporarily preventing a user from connecting


Sometimes, you need to temporarily revoke a 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 this command:

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

There's more…

Here are some additional remarks.

Limiting the number of concurrent connections by a user

The same result can be achieved by setting a connection limit for that user to 0:

pguser=# alter user bob connection limit 0;
ALTER ROLE

To allow 10 concurrent...