On Thu, Mar 5, 2009 at 5:50 AM, paulo matadr <saddoness@yahoo.com.br> wrote:
> I need to procedure to kill users in idle,anybody have this made?
> thanks
> Paulo Moraes
Here's a really primitive bash script to kill off all idle
connections. Run it as postgres:
#!/bin/bash
for i in `psql -U postgres -t -c "select procpid from pg_stat_activity
where current_query like '%<IDLE> in transaction%' and current_query
not ilike '%from pg_stat_activity%';"` ;do
echo $i;
kill $i;
done;
Note that the psql -U line shouldn't be wrapped, unwrap it if you
can't see it in its original glory.
I make no promises that this thing won't eat your machine or anything
else. works on my laptop.