Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3D7CC1EB83EA for ; Thu, 23 Feb 2012 17:38:11 -0400 (AST) Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0gMb-0005Ok-Iw for pgsql-performance@postgresql.org; Thu, 23 Feb 2012 21:38:10 +0000 Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 49E9DE00EC83; Thu, 23 Feb 2012 13:37:56 -0800 (PST) Message-ID: <4F46B1B2.3050105@pinpointresearch.com> Date: Thu, 23 Feb 2012 13:37:54 -0800 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.26) Gecko/20120131 Lightning/1.0b2 Thunderbird/3.1.18 MIME-Version: 1.0 To: Alessandro Gagliardi CC: Peter van Hardenberg , Andy Colson , Thom Brown , pgsql-performance@postgresql.org Subject: Re: set autovacuum=off References: <4F4658CB.3030505@squeakycode.net> <4F467EDF.5090708@pinpointresearch.com> <4F4692FF.3080703@pinpointresearch.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/189 X-Sequence-Number: 46361 On 02/23/2012 01:07 PM, Alessandro Gagliardi wrote: > The second one (a bunch of insert statements within a single > connection). As I mentioned above, I was going to try the temp table > thing, but that wasn't fast enough. COPY might be my next attempt. insert into...; insert into...; insert into...; ... is really (ignoring statement preparation time): begin; insert into...; commit; begin; insert into...; commit; begin; insert into...; commit; It's possible that you might get a nice boost by wrapping the inserts into a transaction: begin; insert into...; insert into...; insert into...; ... commit; This only requires all that disk-intensive stuff that protects your data once at the end instead of 1000 times for you batch of 1000. COPY is even better. I just ran a quick test by restoring a table on my desktop hacking db (untuned, few years old PC, single SATA disk, modest RAM and lots of resource competition). The 22+ million rows restored in 282 seconds which is a rate somewhat north of 78,000 records/second or about 0.13ms/record. You may want to eliminate that trigger, which only seems to exist to silence errors from uniqueness violations, and copy the incoming data into a temp table then move the data with a variant of: INSERT INTO main_table (SELECT ... FROM incoming_table WHERE NOT EXISTS ((SELECT 1 from main_table WHERE ...)) Cheers, Steve