Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id EB7081337B6F for ; Wed, 1 Dec 2010 04:02:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 13194-02 for ; Wed, 1 Dec 2010 08:02:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from megafon.hr (megafon.hr [213.202.104.5]) by mail.postgresql.org (Postfix) with ESMTP id 7A81C1337B64 for ; Wed, 1 Dec 2010 04:02:19 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by megafon.hr (Postfix) with ESMTP id EF4BC250098; Wed, 1 Dec 2010 08:53:51 +0100 (CET) X-Virus-Scanned: ClamAV at megafon.hr Received: from megafon.hr ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nre1bhyQXBTa; Wed, 1 Dec 2010 08:53:46 +0100 (CET) Received: from [192.168.1.94] (klara.megafon.hr [212.92.194.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mike) by megafon.hr (Postfix) with ESMTPSA id C882825009F; Wed, 1 Dec 2010 08:53:46 +0100 (CET) Message-ID: <4CF5FF0A.9040605@megafon.hr> Date: Wed, 01 Dec 2010 08:53:46 +0100 From: Mario Splivalo User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 MIME-Version: 1.0 To: jd@commandprompt.com CC: pgsql-performance@postgresql.org Subject: Re: SELECT INTO large FKyed table is slow References: <4CF24103.8030209@megafon.hr> <1291168052.20631.1963.camel@jd-desktop> In-Reply-To: <1291168052.20631.1963.camel@jd-desktop> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/2 X-Sequence-Number: 41454 On 12/01/2010 02:47 AM, Joshua D. Drake wrote: > On Sun, 2010-11-28 at 12:46 +0100, Mario Splivalo wrote: >> The database for monitoring certain drone statuses is quite simple: >> > >> This is the slow part: >> INSERT INTO drones_history (sample_id, drone_id, drone_log_notice, >> drone_temperature, drone_pressure) >> SELECT * FROM tmpUpdate; >> >> For 100 rows this takes around 2 seconds. For 1000 rows this takes >> around 40 seconds. For 5000 rows this takes around 5 minutes. >> For 50k rows this takes around 30 minutes! Now this is where I start lag >> because I get new CSV every 10 minutes or so. > > Have you considered making the foreign key check deferrable? > Yes, as Mladen Gogala had advised. No noticable change in performance - it's still slow :) But, just for the sake of clarification - I tought that DEFERRABLE would matter if I do a lot of INSERTs, inside a FOR loop or something like that. Since I'm doing INSERT INTO ... SELECT, does it makes any difference? Mario