Re: Cancel a query. - Mailing list pgsql-general

From Matthieu Huin
Subject Re: Cancel a query.
Date
Msg-id 4CEA79D0.60808@wallix.com
Whole thread Raw
In response to Cancel a query.  (Rob Brown-Bayliss <r.brown.bayliss@gmail.com>)
List 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
>

pgsql-general by date:

Previous
From: Vick Khera
Date:
Subject: Re: Cancel a query.
Next
From: Bruce Momjian
Date:
Subject: Re: Fwd: Postgres forums ... take 2