Re: How to Kill IDLE users

From: "Ang Chin Han" <ang(dot)chin(dot)han(at)gmail(dot)com>
To: "Scott Marlowe" <smarlowe(at)g2switchworks(dot)com>
Cc: "Goran Rakic" <gossa(at)disyu(dot)com>, "pgsql general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to Kill IDLE users
Date: 2007-02-28 06:10:30
Message-ID: 8c8854360702272210v4f67d368tcd2de3a6f9943ecd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/28/07, Scott Marlowe <smarlowe(at)g2switchworks(dot)com> wrote:

> select procpid, usename, now()-query_start from pg_stat_activity where
> current_query like '%IDLE%' and now()-query_start > interval '5
> minutes';
>
> to list all the users that have been idle over the interval in the
> list. Using some kind of scripting language, you could then issue kill
> signals to those procpids.

There's always pg_cancel_backend().
http://www.postgresql.org/docs/8.2/static/functions-admin.html

So:

select pg_cancel_backend(procpid) from pg_stat_activity where
current_query = '<IDLE>' and now() - query_start > interval '5
minutes';

should work nicely. I've not really tested that properly though.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shiva Sarna 2007-02-28 06:15:57 supporting 2000 simultaneous connections.
Previous Message Jim C. Nasby 2007-02-28 05:55:16 Re: Difference between UNIQUE constraint vs index