Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 257B3B5F91B for ; Wed, 1 Jun 2011 22:46:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 66301-05 for ; Thu, 2 Jun 2011 01:46:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f46.google.com (mail-pw0-f46.google.com [209.85.160.46]) by mail.postgresql.org (Postfix) with ESMTP id D2F9FB612F5 for ; Wed, 1 Jun 2011 22:46:44 -0300 (ADT) Received: by pwi15 with SMTP id 15so285098pwi.19 for ; Wed, 01 Jun 2011 18:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:content-type:mime-version:subject:from :in-reply-to:date:content-transfer-encoding:message-id:references:to :x-mailer; bh=Jhp3qitBWCgwsiNhhUAZW0IZRJ8cWgOZQs4mt8JwVMs=; b=jXHsFuoRSKsK+5nbuoEfrb+pLvV/+XH8cZC9os+RHGS09mIqiINj/0K7L8Ab5m3OAl xexWZ3Qd8ROyXQJxiw4QcTblSVk5giJKk3TtJzz+Z0SaR6p+iNCSH0BBpKAC30bMpdzy 83e40Q8H4T/HGajo7o69rOvoupsd4+aCbsKKw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=PMB1IUEPtHAiYnRNgVYs9CjxejKWV+6o7i3x3d8jaK2OpxbZGXB401MbkhOws02dxU tqwTVTQIJl9eb9aIlv/otIn4/Si+MOCCJ60+EsHnRszil34ND1upSpUpyo7exGvoc4BC tO2Anex6Qn0LB6VPXhN6nQyQvN2T0pDINvqqY= Received: by 10.68.54.137 with SMTP id j9mr65432pbp.179.1306979204684; Wed, 01 Jun 2011 18:46:44 -0700 (PDT) Received: from [10.2.56.110] (203-206-187-220.perm.iinet.net.au [203.206.187.220]) by mx.google.com with ESMTPS id n1sm125871pbi.47.2011.06.01.18.46.42 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 01 Jun 2011 18:46:43 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Delete performance From: Jarrod Chesney In-Reply-To: <154D1F3C-0605-434C-BA1D-246CF257DB32@gmail.com> Date: Thu, 2 Jun 2011 11:46:38 +1000 Content-Transfer-Encoding: quoted-printable Message-Id: <331CAE09-C7F5-4539-BCDD-5BF216CF9F86@gmail.com> References: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> <4DE598A4.1080100@postnewspapers.com.au> <154D1F3C-0605-434C-BA1D-246CF257DB32@gmail.com> To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.611 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_NJABL_RELAY=2.499, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201106/15 X-Sequence-Number: 43948 On 01/06/2011, at 11:45 AM, Jarrod Chesney wrote: > I'm executing 30,000 single delete statements in one transaction. >=20 > At this point i'm looking into combining the multiple deletes into one = statement and breaking my big transaction into smaller ones of about 100 = deletes or so. >=20 > On 01/06/2011, at 11:40 AM, Craig Ringer wrote: >=20 >> On 1/06/2011 7:11 AM, Pierre C wrote: >>>> If i run 30,000 prepared "DELETE FROM xxx WHERE "ID" =3D ?" = commands it >>>> takes close to 10 minutes. >>>=20 >>> Do you run those in a single transaction or do you use one = transaction >>> per DELETE ? >>>=20 >>> 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. >>=20 >> 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. >>=20 >> If you really must issue individual DELETE commands one-by-one, I = *think* you can use synchronous_commit=3Doff or >>=20 >> SET LOCAL synchronous_commit TO OFF; >>=20 >> See: >>=20 >> http://www.postgresql.org/docs/current/static/runtime-config-wal.html >>=20 >>=20 >> --=20 >> Craig Ringer >>=20 >> Tech-related writing at http://soapyfrogs.blogspot.com/ >=20 Apologies for top posting, Sorry.=