Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 053599FBDDF for ; Wed, 18 Jul 2007 16:08:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 49437-05 for ; Wed, 18 Jul 2007 16:08:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pat.uio.no (pat.uio.no [129.240.10.15]) by postgresql.org (Postfix) with ESMTP id 284279FB5DD for ; Wed, 18 Jul 2007 16:08:50 -0300 (ADT) Received: from mail-mx9.uio.no ([129.240.10.39]) by pat.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IBEtF-0007nQ-RY for pgsql-performance@postgresql.org; Wed, 18 Jul 2007 21:08:49 +0200 Received: from smtp.uio.no ([129.240.10.9] helo=mail-mx9.uio.no) by mail-mx9.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IBEtF-0002vR-Ew for pgsql-performance@postgresql.org; Wed, 18 Jul 2007 21:08:49 +0200 Received: from 113.80-203-240.nextgentel.com ([80.203.240.113] helo=[10.0.0.128]) by mail-mx9.uio.no with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1IBEtF-0002vA-5l for pgsql-performance@postgresql.org; Wed, 18 Jul 2007 21:08:49 +0200 Message-ID: <469E6518.5000203@ifi.uio.no> Date: Wed, 18 Jul 2007 21:08:08 +0200 From: Thomas Finneid User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: insert vs select into performance References: <469D1AD3.9030004@ifi.uio.no> <469D342B.7080103@ifi.uio.no> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-UiO-SPF-Received: X-UiO-Resend: resent X-UiO-SPF-Received: X-UiO-Spam-info: not spam, SpamAssassin (score=0.0, required=12.0, autolearn=disabled, AWL=0.034) X-UiO-Scanned: 02C18117F28F8C60A64A0825B38CAEC82F36E60F X-UiO-SPAM-Test: remote_host: 129.240.10.9 spam_score: 0 maxlevel 200 minaction 2 bait 0 mail/h: 66 total 2889799 max/h 8345 blacklist 0 greylist 0 ratelimit 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/226 X-Sequence-Number: 25910 PFC wrote: >> Unfortunately its not fast enough, it needs to be done in no more than >> 1-2 seconds, ( and in production it will be maybe 20-50 columns of >> data, perhaps divided over 5-10 tables.) >> Additionally it needs to scale to perhaps three times as many columns >> and perhaps 2 - 3 times as many rows in some situation within 1 seconds. >> Further on it needs to allow for about 20 - 50 clients reading much of >> that data before the next batch of data arrives. > > Wow. What is the application ? Geological surveys, where they perform realtime geo/hydro-phone shots of areas of the size of 10x10km every 3-15 seconds. > test=> CREATE OR REPLACE FUNCTION test_insert( ) > RETURNS VOID > LANGUAGE plpgsql > AS > $$ > DECLARE > _i INTEGER; > BEGIN > FOR _i IN 0..100000 LOOP > INSERT INTO test (a,b,c,d,e,f) VALUES (1,2,3,4,5, _i); > END LOOP; > END; > $$; > CREATE FUNCTION > Temps : 51,948 ms > > test=> SELECT test_insert(); > test_insert > ------------- > > (1 ligne) > > Temps : 1885,382 ms I tested this one and it took 4 seconds, compared to the jdbc insert which took 14 seconds, so its a lot faster. but not as fast as the SELECT INTO. I also tested an INSERT INTO FROM SELECT, which took 1.8 seconds, now we are starting to talk about real performance. > However COPY is much faster because the parsing overhead and > de-escaping of data is faster. COPY is optimized for throughput. > > So, advice : > > For optimum throughput, have your application build chunks of data > into text files and use COPY. Or if your client lib supports the copy > interface, use it. I did test COPY, i.e. the jdbc COPY patch for pg 8.1, it performs at approx 1.8 seconds :) The test was done with text input, I am going to test it with binary input, which I expect will increase the performance with 20-50%. All these test have ben performed on a laptop with a Kubuntu 6.10 version of pg 8.1 without any special pg performance tuning. So I expect that compiling lates pg and doing some tuning on it and testing it on the a representative server will give it an additional boost in performance. The key here is that with abundance in performance, I can experiment with the solution in a completely different way than if I had any "artificial" restrictions. > You will need a fast disk system with xlog and data on separate > disks, several CPU cores (1 insert thread will max out 1 core, use the > others for selects), lots of RAM so index updates don't need to seek, > and tuning of bgwriter and checkpoints to avoid load spikes. will have a look at it. regards thomas