Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdVKK-0000M7-TI for pgsql-performance@arkaria.postgresql.org; Wed, 28 Nov 2012 00:16:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TdVKJ-0005H4-Lw for pgsql-performance@arkaria.postgresql.org; Wed, 28 Nov 2012 00:16:31 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdVKH-0005Gy-9y for pgsql-performance@postgresql.org; Wed, 28 Nov 2012 00:16:30 +0000 Received: from nm38-vm8.bullet.mail.gq1.yahoo.com ([98.136.217.79]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdVKE-0008SX-Rl for pgsql-performance@postgresql.org; Wed, 28 Nov 2012 00:16:27 +0000 Received: from [98.137.12.61] by nm38.bullet.mail.gq1.yahoo.com with NNFMP; 28 Nov 2012 00:16:25 -0000 Received: from [98.136.185.192] by tm6.bullet.mail.gq1.yahoo.com with NNFMP; 28 Nov 2012 00:16:25 -0000 Received: from [127.0.0.1] by smtp101-mob.biz.mail.gq1.yahoo.com with NNFMP; 28 Nov 2012 00:16:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1354061785; bh=S72pt2qZov7HhV3knDs9TkzwxQr8s7o+XW6YX53EznU=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=Wc9ldDmkYikMpe/vXDDjPr1xmw/5kQVT/MTPcWQebH51MRt8zSwcXWloUvZuL7FKBimCHXSdfd8q/VdAFo0p/H6S1Oa/rQt0Yn4k2MeufugiKYz/FWQVU4xAY20davhvlZolWAKCB14/vHOZgdmPpFi18i4xnAVlF5oB/iNGiRk= X-Yahoo-Newman-Id: 762091.16578.bm@smtp101-mob.biz.mail.gq1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: omLu.IcVM1n5eWK.kVoDDtbqm1za91eIFz8_sOn.SqvbZMp yXDbwVsr8lkQOwGubUE.wgJsdsheBTHTI0x_1vONIK4bOvWDk1KAMDSpw857 68N_F5ZrqRrvkf_G3u34pJoiOqAQfqk_aWjgq224ul2mkO0pVFJW2WMSe_BN hBgqE7FUZ9LBfVlaaQB2wLgeJbWh.x5x3S5tQ_TWb.A9zzmtV7R8BFzfSNlA ts9KYnnEWSSPyY50510DaJID9dPLrBa279EcC1TSG3m_aLzqf26ivkfS_8o4 jrM7B8nBPlRvqn2w22z6UP4ayJMiksJRPwZUnSERWMFx.aq4iv7IHNmWDq9M dqVDOH1mTmmN382L.pS5EedqKSC0hL6Tlny_9eA_HeuMkDjOZhnsPkPF4QtU HnjVTc_ySmWMeIG0r6dq2iiGbyVs5M0kt1lc51w2100W_kbfPdhHwqN6Ggqn ChHZCS92N.K9cVEpACslrb6I74CNo9JHx X-Yahoo-SMTP: avz0i7CswBCx58rKMHFb2s7t.tfwS0w- Received: from [10.234.70.44] (bob_lunney@174.231.149.197 with xymcookie) by smtp101-mob.biz.mail.gq1.yahoo.com with SMTP; 27 Nov 2012 16:16:25 -0800 PST References: In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary=Apple-Mail-AD076FF1-FF4E-4562-B289-440FED34441B Message-Id: <2000E26E-35FC-4801-90F3-3CFBDA7B41DF@yahoo.com> Cc: "pgsql-performance@postgresql.org" X-Mailer: iPhone Mail (9B206) From: Bob Lunney Subject: Re: Savepoints in transactions for speed? Date: Tue, 27 Nov 2012 18:16:23 -0600 To: Mike Blackwell X-Pg-Spam-Score: -2.3 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --Apple-Mail-AD076FF1-FF4E-4562-B289-440FED34441B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Mike, Is there anything that the 1.5 million rows have in common that would allow y= ou to use partitions? if so, you could load the new data into a partition a= t your leisure, start a transaction, alter the partition table with the old d= ata to no longer inherit from the parent, alter the new partition table to inherit from the parent, commit, then drop the old table. This operation wo= uld be very fast, the users probably won't even notice.=20 Bob Lunney On Nov 27, 2012, at 4:04 PM, Mike Blackwell wrote: > I need to delete about 1.5 million records from a table and reload it in o= ne transaction. The usual advice when loading with inserts seems to be grou= p them into transactions of around 1k records. Committing at that point wou= ld leave the table in an inconsistent state. Would issuing a savepoint ever= y 1k or so records negate whatever downside there is to keeping a transactio= n open for all 1.5 million records, or just add more overhead? >=20 > The data to reload the table is coming from a Perl DBI connection to a dif= ferent database (not PostgreSQL) so I'm not sure the COPY alternative applie= s here. >=20 > Any suggestions are welcome. >=20 >=20 > Mike --Apple-Mail-AD076FF1-FF4E-4562-B289-440FED34441B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Mike,

=
Is there anything that the 1.5 million rows have in common that would a= llow you to use partitions?  if so, you could load the new data into a p= artition  at your leisure, start a transaction, alter the partition tab= le with the old data to no longer inherit from the parent, alter the new par= tition table to
inherit from the parent, commit, then drop the old= table.  This operation would be very fast, the users probably won't ev= en notice. 

Bob Lunney

On Nov 27, 2012, at 4= :04 PM, Mike Blackwell <mike.bl= ackwell@rrd.com> wrote:

I need to delete about 1.5 million records from a table and reload= it in one transaction.  The usual advice when loading with inserts see= ms to be group them into transactions of around 1k records.  Committing= at that point would leave the table in an inconsistent state.  Would i= ssuing a savepoint every 1k or so records negate whatever downside there is t= o keeping a transaction open for all 1.5 million records, or just add more o= verhead?

The data to reload the table is coming from a Perl DBI connec= tion to a different database (not PostgreSQL) so I'm not sure the COPY alter= native applies here.

Any suggestions are welcome.


Mike

=
= --Apple-Mail-AD076FF1-FF4E-4562-B289-440FED34441B--