DROP ROLE: how to detect active sessions? - Mailing list pgsql-admin

From Ken Lalonde
Subject DROP ROLE: how to detect active sessions?
Date
Msg-id 61A975CD-61CC-40CF-87CA-46BEEC1CEEAF@gap.ca
Whole thread Raw
Responses Re: DROP ROLE: how to detect active sessions?
List pgsql-admin
I need to track db activity by role.   All web-related connections to the db use the same user name.
When a user logs in via the web, the application code runs:
    SET ROLE "n"
where n is the ID value for the user in the "users" table.
(These numeric roles are created dynamically as needed).
We can then use the value of "current_user" to track activity.

So far so good.

The problem happens when we periodically drop roles for inactive users.
If I run DROP ROLE "n", and there happens to be an active session for that role,
we have a problem: in that session, "select current_user" fails with "invalid role OID: nnnn".

Is there any way to determine if a given role has any active sessions?

Thanks a bunch,

Ken Lalonde
Gap Adventures, Toronto

pgsql-admin by date:

Previous
From: Kieren Scott
Date:
Subject: Re: Restricting schema sizes
Next
From: Tom Lane
Date:
Subject: Re: DROP ROLE: how to detect active sessions?