Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 239B064FCF4 for ; Thu, 7 Aug 2008 04:58:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 18031-03 for ; Thu, 7 Aug 2008 04:58:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by postgresql.org (Postfix) with ESMTP id 6C75764FCEA for ; Thu, 7 Aug 2008 04:58:04 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay04.plus.net with esmtp (Exim) id 1KR0Nl-0003oY-0c; Thu, 07 Aug 2008 08:58:01 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id D90AA274065; Thu, 7 Aug 2008 08:58:00 +0100 (BST) Message-ID: <489AAB08.9080409@archonet.com> Date: Thu, 07 Aug 2008 08:58:00 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.16 (X11/20080707) MIME-Version: 1.0 To: Volkan YAZICI CC: pgsql-performance@postgresql.org Subject: Re: Unexpectedly Long DELETE Wait References: <874p5xwe3g.fsf@alamut.mobiliz.com.tr> In-Reply-To: <874p5xwe3g.fsf@alamut.mobiliz.com.tr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: de41ac1a5207bdb402c15795d8620276 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/29 X-Sequence-Number: 30910 Volkan YAZICI wrote: > Hi, > > Below command has been running since ~700 minutes in one of our > PostgreSQL servers. > > DELETE FROM mugpsreglog > WHERE NOT EXISTS (SELECT 1 > FROM mueventlog > WHERE mueventlog.eventlogid = mugpsreglog.eventlogid); > > Seq Scan on mugpsreglog (cost=0.00..57184031821394.73 rows=6590986 width=6) > Filter: (NOT (subplan)) > SubPlan > -> Seq Scan on mueventlog (cost=0.00..4338048.00 rows=1 width=0) > Filter: (eventlogid = $0) Ouch - look at the estimated cost on that! > And there isn't any constraints (FK/PK), triggers, indexes, etc. on any > of the tables. (We're in the phase of a migration, many DELETE commands > similar to above gets executed to relax constraints will be introduced.) Well there you go. Add an index on eventlogid for mugpsreglog. Alternatively, if you increased your work_mem that might help. Try SET work_mem='64MB' (or even higher) before running the explain and see if it tries a materialize. For situations like this where you're doing big one-off queries you can afford to increase resource limits. -- Richard Huxton Archonet Ltd