Received: from maia.hub.org (unknown [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 500D61337B68 for ; Thu, 21 Oct 2010 15:09:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 48670-01-6 for ; Thu, 21 Oct 2010 18:09:18 +0000 (UTC) X-Greylist: delayed 00:05:03.636915 by SQLgrey-1.7.6 Received: from mailroom.gap.ca (mailroom.gap.ca [205.207.123.201]) by mail.postgresql.org (Postfix) with ESMTP id 8E2DE1337B8B for ; Thu, 21 Oct 2010 15:09:17 -0300 (ADT) Received: from mailroom.gap.ca (127.0.0.1) by mailroom.gap.ca (MlfMTA v3.2r9) id ho1vk00171so for ; Thu, 21 Oct 2010 13:53:19 -0400 (envelope-from ) Received: from gap.ca ([10.100.10.40]) by mailroom.gap.ca (SonicWALL 7.2.1.2841) with ESMTP; Thu, 21 Oct 2010 13:53:19 -0400 Received: from [10.100.50.164] (HELO dhcp164.gap.ca) by gap.ca (CommuniGate Pro SMTP 5.2.14) with ESMTPS id 8604964 for pgsql-admin@postgresql.org; Thu, 21 Oct 2010 14:04:11 -0400 From: Ken Lalonde Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: DROP ROLE: how to detect active sessions? Date: Thu, 21 Oct 2010 14:04:11 -0400 Message-Id: <61A975CD-61CC-40CF-87CA-46BEEC1CEEAF@gap.ca> To: pgsql-admin@postgresql.org Mime-Version: 1.0 (Apple Message framework v1081) X-Mailer: Apple Mail (2.1081) X-Mlf-Version: 7.2.1.2841 X-Mlf-UniqueId: o201010211753190075186 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/161 X-Sequence-Number: 35902 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=