Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 9E402B620F0 for ; Tue, 31 May 2011 22:45:19 -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 07814-02-2 for ; Wed, 1 Jun 2011 01:45:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 089AFB61E61 for ; Tue, 31 May 2011 22:45:09 -0300 (ADT) Received: by pvg12 with SMTP id 12so2294137pvg.19 for ; Tue, 31 May 2011 18:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:mime-version:content-type:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to:x-mailer; bh=1mewK/ewC8bBvzspMhin7WeXf0jelf1p36C4vOPyg6Q=; b=U9z1mLAUa0t7PLRaNv3u+Rir/HFAMIinnao40qyZqq+TWzRESN5D2oKPX9rPK3+cvo 4ipsHR/hYh5S5bkyveB5iRqEjTQOCcpADBfSsRS2TZBWt4LroU2Htr/eX89JSWICaKH/ N6wfE8fruQSbVWDTk+kuCRh8RqlTYDMbAlsVw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; b=AeToniNFZpFzDntRQ0W/Lti5A8R9AzExhYrAX6S0sb8a1XCunHEdyVQBr/UvqSB3zS sg0tH8RbgIQ0rTPzFvu2HN49gauXmXVchje9o6P1rFJ2Yl8yfzSfpENCWlvdY2lJAqNL b80LoJ9GQXhRMmWgDaD7edTFilp4srSF0zi6M= Received: by 10.68.20.38 with SMTP id k6mr2808659pbe.410.1306892709788; Tue, 31 May 2011 18:45:09 -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 k9sm549672pbc.38.2011.05.31.18.45.07 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 May 2011 18:45:08 -0700 (PDT) Subject: Re: Delete performance Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Jarrod Chesney In-Reply-To: <4DE598A4.1080100@postnewspapers.com.au> Date: Wed, 1 Jun 2011 11:45:04 +1000 Cc: Pierre C , pgsql-performance@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <154D1F3C-0605-434C-BA1D-246CF257DB32@gmail.com> References: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> <4DE598A4.1080100@postnewspapers.com.au> To: Craig Ringer X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.601 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 X-Spam-Level: X-Archive-Number: 201105/424 X-Sequence-Number: 43933 I'm executing 30,000 single delete statements in one transaction. 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. On 01/06/2011, at 11:40 AM, Craig Ringer wrote: > 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/