X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 1B92D9FA9BD for ; Tue, 2 May 2006 23:09:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82665-07 for ; Tue, 2 May 2006 23:09:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx.sat.rackspace.com (mx.sat.rackspace.com [64.39.1.214]) by postgresql.org (Postfix) with ESMTP id 6512E9FA2C7 for ; Tue, 2 May 2006 23:09:37 -0300 (ADT) Received: from mail.rackspace.com (mail.rackspace.com [64.39.2.181]) by mx.sat.rackspace.com (8.13.6/8.13.6) with ESMTP id k4329ZGo006493 for ; Tue, 2 May 2006 21:09:36 -0500 (envelope-from wreese@rackspace.com) Received: from [192.168.10.8] (vpn113-66.sat.rackspace.com [10.1.113.66]) (authenticated bits=0) by mail.rackspace.com (8.13.1/8.13.1) with ESMTP id k4329YRc005803 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NO) for ; Tue, 2 May 2006 21:09:34 -0500 Mime-Version: 1.0 (Apple Message framework v749.3) In-Reply-To: <1146614476.2471.28.camel@laptop.gunduz.org> References: <4457E918.10007@drivefaster.net> <1146614476.2471.28.camel@laptop.gunduz.org> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <6F323559-FD45-4E8A-9DDB-D3775E1C8716@rackspace.com> Content-Transfer-Encoding: 7bit From: Will Reese Subject: Re: Killing long-running queries Date: Tue, 2 May 2006 21:09:14 -0500 To: PostgreSQL Performance X-Mailer: Apple Mail (2.749.3) X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='__C230066_P5 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0' X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/68 X-Sequence-Number: 18855 There is also the statement_timeout setting in postgresql.conf, but you have to be careful with this setting. I'm not sure about postgres 8.0 or 8.1, but in 7.4.5 this setting will terminate the COPY statements used by pg_dumpall for backups. So I actually use the pg_stat_activity table to kill long running queries or idle in transactions that are hanging around (very bad for vacuum). For example, you can do something like this to kill off idle in transactions that are truly idle for more than 1 hour... psql -U postgres -A -t -c "select procpid from pg_stat_activity where current_query ilike '%idle in transaction%' and query_start < now() - interval '1 hour'" template1 | xargs kill Just throw that in your crontab to run every few minutes, redirect standard error to /dev/null, and quit worrying about vacuum not reclaiming space because some developer's code fails to commit or rollback a transaction. Just be careful you aren't killing off processes that are actually doing work. :) -- Will Reese http://blog.rezra.com On May 2, 2006, at 7:01 PM, Devrim GUNDUZ wrote: > Hi, > > On Tue, 2006-05-02 at 17:19 -0600, Dan Harris wrote: >> Is there some way I can just kill a query and not risk breaking >> everything else when I do it? > > Use pg_stat_activity view to find the pid of the process (pidproc > column) and send the signal to that process. I think you are now > killing > postmaster, which is wrong. > > Regards, > -- > The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 > PostgreSQL Replication, Consulting, Custom Development, 24x7 support > Managed Services, Shared and Dedicated Hosting > Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/ > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org