Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 102E416B0CAD for ; Mon, 19 Dec 2011 14:44:56 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RciCj-00023F-Iv for pgsql-admin@postgresql.org; Mon, 19 Dec 2011 18:44:55 +0000 Received: by iaeh11 with SMTP id h11so8923763iae.19 for ; Mon, 19 Dec 2011 10:44:40 -0800 (PST) Received: by 10.50.17.168 with SMTP id p8mr28448311igd.20.1324320280113; Mon, 19 Dec 2011 10:44:40 -0800 (PST) Received: from Craig-Jamess-MacBook-Pro.local (wsip-70-167-122-86.sd.sd.cox.net. [70.167.122.86]) by mx.google.com with ESMTPS id l28sm70017931ibc.3.2011.12.19.10.44.38 (version=SSLv3 cipher=OTHER); Mon, 19 Dec 2011 10:44:39 -0800 (PST) Message-ID: <4EEF869D.9060703@emolecules.com> Date: Mon, 19 Dec 2011 10:46:53 -0800 From: Craig James User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: Giving postgres roles 'sudo'-like access References: <4EEF7C9D.60006@megafon.hr> In-Reply-To: <4EEF7C9D.60006@megafon.hr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/97 X-Sequence-Number: 38855 On 12/19/11 10:04 AM, Mario Splivalo wrote: > I need to have postgres role to be able to cancel queries run by that > same role. > > I know that I can kill the client connection that started the query, but > I also need to have that role connect to postgres and kill some of it's > running queries. > > It's on postgres 9.1.1, running on Debian Squeeze. > > One idea that comes to mind is to have a special user account on the box > which would have sudo privileges to the script which will issue 'sh > postgres -c 'psql -c "select pg_cancel_backend()"', but before that > run checks that is actually owned by correct role, etc, etc. But, > all that seems very fishy. > > Has anyone had similar requests, and maybe solved them somehow? Yes. First of all, you really don't want to do this. If there's any other way, find it. In our case, we use a third-party library that sometimes gets stuck on problems that would take a virtually infinite time to solve, and for reasons having to do with NP-complete theory, you can't easily detect them ahead of time. So.... Backend Postgres processes run as the Postgres user, so they have permission to kill each other. You write an add-on function that just kills a process: select my_kill_backend(pid); Naturally, this is very dangerous. There are all sorts of security implications. You want to use signal 2 or 15, not 9. And so forth. Craig