Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E692BB5DC2F for ; Tue, 31 May 2011 20:12:03 -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 42363-01 for ; Tue, 31 May 2011 23:11:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 27.mail-out.ovh.net (3.27.mail-out.ovh.net [46.105.56.209]) by mail.postgresql.org (Postfix) with SMTP id 38D93B60284 for ; Tue, 31 May 2011 20:11:52 -0300 (ADT) Received: (qmail 13365 invoked by uid 503); 1 Jun 2011 00:08:16 -0000 Received: from b9.ovh.net (HELO mail193.ha.ovh.net) (213.186.33.59) by 27.mail-out.ovh.net with SMTP; 1 Jun 2011 00:08:08 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 1 Jun 2011 01:11:42 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 1 Jun 2011 01:11:41 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: pgsql-performance@postgresql.org, "Jarrod Chesney" Subject: Re: Delete performance References: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> Date: Wed, 01 Jun 2011 01:11:39 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> User-Agent: Opera Mail/11.10 (Linux) X-Ovh-Tracer-Id: 8479433675511498289 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-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201105/421 X-Sequence-Number: 43930 > If i run 30,000 prepared "DELETE FROM xxx WHERE "ID" = ?" commands it > takes close to 10 minutes. Do you run those in a single transaction or do you use one transaction per DELETE ? In the latter case, postgres will ensure each transaction is commited to disk, at each commit. Since this involves waiting for the physical I/O to happen, it is slow. If you do it 30.000 times, it will be 30.000 times slow. Note that you should really do : DELETE FROM table WHERE id IN (huge list of ids). or DELETE FROM table JOIN VALUES (list of ids) ON (...) Also, check your foreign keys using cascading deletes have indexes in the referencing tables. Without an index, finding the rows to cascade-delete will be slow.