Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 6B0F4640CBE for ; Mon, 17 May 2010 07:17:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 17932-08 for ; Mon, 17 May 2010 10:17:16 +0000 (UTC) X-Greylist: delayed 00:06:38.508467 by SQLgrey-1.7.6 Received: from 68.mail-out.ovh.net (68.mail-out.ovh.net [91.121.185.69]) by mail.postgresql.org (Postfix) with SMTP id A159E640CBA for ; Mon, 17 May 2010 07:17:15 -0300 (ADT) Received: (qmail 16090 invoked by uid 503); 17 May 2010 10:15:51 -0000 Received: from 63.mail-out.ovh.net (91.121.185.56) by 68.mail-out.ovh.net with SMTP; 17 May 2010 10:15:51 -0000 Received: (qmail 1554 invoked by uid 503); 17 May 2010 10:18:54 -0000 Received: from b9.ovh.net (HELO mail176.ha.ovh.net) (213.186.33.59) by 63.mail-out.ovh.net with SMTP; 17 May 2010 10:18:54 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 17 May 2010 10:10:33 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO immo.peufeu.com) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 17 May 2010 10:10:32 -0000 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: thilo , pgsql-performance@postgresql.org Subject: Re: Slow Bulk Delete References: Date: Mon, 17 May 2010 12:10:31 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: User-Agent: Opera Mail/10.10 (Linux) X-Ovh-Tracer-Id: 1591740993366459982 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Ovh-Tracer-Id: 1681812986900055601 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201005/87 X-Sequence-Number: 38671 > DELETE FROM table1 WHERE table2_id = ? For bulk deletes, try : DELETE FROM table1 WHERE table2_id IN (list of a few thousands ids) - or use a JOIN delete with a virtual VALUES table - or fill a temp table with ids and use a JOIN DELETE This will save cliet/server roundtrips. Now, something that can make a DELETE very slow is a non-indexed ON DELETE CASCADE foreign key : when you DELETE FROM table1 and it cascades to a DELETE on table2, and you forget the index on table2. Also check the time spent in triggers. Do you have a GIN index ?