Re: Cancel a query.

From: Matthieu Huin <matthieu(dot)huin(at)wallix(dot)com>
To: pgsql-general(at)postgresql(dot)org, r(dot)brown(dot)bayliss(at)gmail(dot)com
Subject: Re: Cancel a query.
Date: 2010-11-22 14:10:24
Message-ID: 4CEA79D0.60808@wallix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You could create a function calling that query with "Security Definer"
(the function will be called with the privileges of the user that
created the function) :

CREATE OR REPLACE FUNCTION stop_query(myprocpid int)
RETURNS BOOLEAN AS $$
DECLARE
b boolean;
BEGIN
SELECT pg_cancel_backend(myprocpid) INTO b;
RETURN b;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

Make sure this function is created with the super user. You can then
call it with any user.

Hope this helps.

Matthieu

Le 20/11/2010 06:41, Rob Brown-Bayliss a écrit :
> Hi
>
> I have some code using psycopg in python. Connecting in async mode.
>
> I am trying to catch time outs etc, basically after a set amount of
> time I am assuming something has failed.
>
> I then want to use "select pg_cancel_backend(15209);" to cancel the
> query. But I can't unless I am connected as the postgres super user.
>
> How can I get my app to cancel one of it's own queries while logged on
> as a normal user?
>
>
>
> Thanks.
>
> --
>
> Rob
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2010-11-22 14:51:03 Re: Cancel a query.
Previous Message Bruce Momjian 2010-11-22 14:05:50 Re: Fwd: Postgres forums ... take 2