Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C68BDB620BC for ; Tue, 31 May 2011 22:43:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 01536-01-10 for ; Wed, 1 Jun 2011 01:43:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id 5F198B8879C for ; Tue, 31 May 2011 22:41:03 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 6965910D; Tue, 31 May 2011 21:41:03 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id YLSL-Pzjx0gg; Tue, 31 May 2011 21:41:02 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 86AFF2D; Tue, 31 May 2011 21:41:02 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 5E73DAEFB4; Wed, 1 Jun 2011 09:41:01 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id t78vslr0BqyB; Wed, 1 Jun 2011 09:40:56 +0800 (WST) Received: from [10.1.1.3] (unknown [124.169.247.86]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id DEDD2AEFB3; Wed, 1 Jun 2011 09:40:55 +0800 (WST) Message-ID: <4DE598A4.1080100@postnewspapers.com.au> Date: Wed, 01 Jun 2011 09:40:52 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Pierre C CC: pgsql-performance@postgresql.org, Jarrod Chesney Subject: Re: Delete performance References: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/423 X-Sequence-Number: 43932 On 1/06/2011 7:11 AM, Pierre C wrote: >> 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. Not only that, but if you're doing it via some application the app has to wait for Pg to respond before it can send the next query. This adds even more delay, as do all the processor switches between Pg and your application. If you really must issue individual DELETE commands one-by-one, I *think* you can use synchronous_commit=off or SET LOCAL synchronous_commit TO OFF; See: http://www.postgresql.org/docs/current/static/runtime-config-wal.html -- Craig Ringer Tech-related writing at http://soapyfrogs.blogspot.com/