Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id ADA531337B51 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.243]) (amavisd-maia, port 10024) with ESMTP id 68923-03 for ; Wed, 1 Dec 2010 08:02:19 +0000 (UTC) X-Greylist: delayed 00:10:00.16648 by SQLgrey-1.7.6 Received: from megafon.hr (megafon.hr [213.202.104.5]) by mail.postgresql.org (Postfix) with ESMTP id 7632D1337B39 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 3AC1C2500A0; Wed, 1 Dec 2010 08:52:15 +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 YFZmJqzqaHkH; Wed, 1 Dec 2010 08:52:10 +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 17CA825009F; Wed, 1 Dec 2010 08:52:09 +0100 (CET) Message-ID: <4CF5FEA9.3000900@megafon.hr> Date: Wed, 01 Dec 2010 08:52:09 +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: Pierre C CC: Mladen Gogala , "pgsql-performance@postgresql.org" Subject: Re: SELECT INTO large FKyed table is slow References: <4CF24103.8030209@megafon.hr> <4CF5259C.8000306@vmsinfo.com> <4CF59017.1090705@megafon.hr> In-Reply-To: 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/1 X-Sequence-Number: 41453 On 12/01/2010 01:51 AM, Pierre C wrote: > >> Now I tried removing the constraints from the history table (including >> the PK) and the inserts were fast. After few 'rounds' of inserts I >> added constraints back, and several round after that were fast again. >> But then all the same. Insert of some 11k rows took 4 seconds (with >> all constraints) and now the last one of only 4k rows took one minute. >> I did vacuum after each insert. >> >> >> Mario > > Hm, so for each line of drones_history you insert, you also update the > correspoding drones table to reflect the latest data, right ? Yes. > How many times is the same row in "drones" updated ? ie, if you insert N > rows in drones_nistory, how may drone_id's do you have ? Just once. If I have 5000 lines in CSV file (that I load into 'temporary' table using COPY) i can be sure that drone_id there is PK. That is because CSV file contains measurements from all the drones, one measurement per drone. I usualy have around 100 new drones, so I insert those to drones and to drones_history. Then I first insert into drones_history and then update those rows in drones. Should I try doing the other way around? Although, I think I'm having some disk-related problems because when inserting to the tables my IO troughput is pretty low. For instance, when I drop constraints and then recreate them that takes around 15-30 seconds (on a 25M rows table) - disk io is steady, around 60 MB/s in read and write. It just could be that the ext3 partition is so fragmented. I'll try later this week on a new set of disks and ext4 filesystem to see how it goes. Mario