How to disconnect NOLOGIN users from PostgreSQL

In this article, we will see how to disconnect NOLOGIN users from PostgreSQL. In order to make sure that all users whose login privileges has been revoked are disconnected right away.

Query to disconnect NOLOGIN users from PostgreSQL:

SELECT pg_terminate_backend(pid) FROM pg_stat_activity sa JOIN pg_roles r ON sa.usename=r.rolname and not rolcanlogin;

Continue reading How to disconnect NOLOGIN users from PostgreSQL