Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdUYP-0007vm-IJ for pgsql-performance@arkaria.postgresql.org; Tue, 27 Nov 2012 23:27:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TdUYO-00056A-Hf for pgsql-performance@arkaria.postgresql.org; Tue, 27 Nov 2012 23:27:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdUYB-0004vG-SN for pgsql-performance@postgresql.org; Tue, 27 Nov 2012 23:26:48 +0000 Received: from misc.wordtothewise.com ([184.105.179.154] helo=m.wordtothewise.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdUY7-0002tT-U5 for pgsql-performance@postgresql.org; Tue, 27 Nov 2012 23:26:47 +0000 Received: from [192.168.80.21] (204.11.227.194.static.etheric.net [204.11.227.194]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: steve) by m.wordtothewise.com (Postfix) with ESMTPSA id 899862DD88 for ; Tue, 27 Nov 2012 15:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wordtothewise.com; s=1.wttw; t=1354058800; bh=kn65TpX4FMAkemW59ISIRT+7Xsd8oTLqgPzQcWhsYnA=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date: Content-Transfer-Encoding:Message-Id:References:To; b=XxLNKAtlUiA6lxYy6f/5GZxcmeMFY9cfZq1YvLHznpJ73VTIJ6KIT1wNjRMypKiMS 8xzyeI/y7rnSbswv/J4IAgQhXClf6mm+lI8YmQkP0/x7AJ1/qSIfveOfLV3rLSjFGh EGey+qEybDZCHQmGa1cMPGDCqxveXt1tPVyvRPL4= Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Savepoints in transactions for speed? From: Steve Atkins In-Reply-To: Date: Tue, 27 Nov 2012 15:26:26 -0800 Content-Transfer-Encoding: quoted-printable Message-Id: <332684FA-4859-4B13-9EC7-94B75EE7BB99@blighty.com> References: To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -1.9 (-) 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 On Nov 27, 2012, at 2:04 PM, Mike Blackwell 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 gr= oup them into transactions of around 1k records. Committing at that point = would leave the table in an inconsistent state.=20 I'd probably just do the whole thing in one transaction.=20 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 d= oing a big transaction, in the way some other databases will. Long running transactions will interfere with vacuuming, but inserting a co= uple of million rows shouldn't take that long. > Would issuing a savepoint every 1k or so records negate whatever downsid= e there is to keeping a transaction open for all 1.5 million records, or ju= st 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 en= tire transaction, they're great, but that's about it. > The data to reload the table is coming from a Perl DBI connection to a di= fferent database (not PostgreSQL) so I'm not sure the COPY alternative appl= ies 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 mil= lions of rows) bulk inserts. It's not as fast as you can get, but it's prob= ably as fast as you can get with perl. Cheers, Steve --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance