pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: Savepoints in transactions for speed?
Date: Tue, 27 Nov 2012 15:26:26 -0800
Message-ID: <332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com> (raw)
In-Reply-To: <CANPAkgs_LvZV-fabTNN-ahiVcwSBAyOnArw1v+QbCePg7on6ZA@mail.gmail.com>
References: <CANPAkgs_LvZV-fabTNN-ahiVcwSBAyOnArw1v+QbCePg7on6ZA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>


On Nov 27, 2012, at 2:04 PM, Mike Blackwell <mike.blackwell@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 seems to be group them into transactions of around 1k records.  Committing at that point would leave the table in an inconsistent state. 

I'd probably just do the whole thing in one transaction. 

Do you have specific reasons you want to avoid a long transaction, or just relying on rules of thumb? Postgresql isn't going to run out of resources doing a big transaction, in the way some other databases will.

Long running transactions will interfere with vacuuming, but inserting a couple of million rows shouldn't take that long.

>  Would issuing a savepoint every 1k or so records negate whatever downside there is to keeping a transaction open for all 1.5 million records, or just add more overhead?


Savepoints are going to increase overhead and have no effect on the length of the transaction. If you want to catch errors and not have to redo the entire transaction, they're great, but that's about it.

> The data to reload the table is coming from a Perl DBI connection to a different database (not PostgreSQL) so I'm not sure the COPY alternative applies here.

COPY works nicely from perl:

$dbh->do("COPY foo FROM STDIN");
$dbh->pg_putcopydata("foo\tbar\tbaz\n");
$dbh->pg_putcopyend();

The details are in DBD::Pg. I use this a lot for doing big-ish (tens of millions of rows) bulk inserts. It's not as fast as you can get, but it's probably as fast as you can get with perl.

Cheers,
  Steve



-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (22+ messages)  latest in thread

Message-ID: <332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com>
Permalink:  ../332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com/
Also on:    postgresql.org/message-id/332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: steve@blighty.com
  Subject: Re: Savepoints in transactions for speed?
  In-Reply-To: <332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox