Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id C109B9FB40D for ; Fri, 13 Oct 2006 05:55:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 61677-07 for ; Fri, 13 Oct 2006 08:55:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from oss4u.com (mail.andrea-schroeder.com [64.142.76.151]) by postgresql.org (Postfix) with SMTP id C379A9FB403 for ; Fri, 13 Oct 2006 05:55:08 -0300 (ADT) Received: (qmail 24415 invoked from network); 13 Oct 2006 08:50:05 -0000 Received: from tiburon.oss4u.com (192.168.1.4) by gw.oss4u.com (192.168.1.1) with ESMTP; 13 Oct 2006 08:50:05 -0000 From: "Uwe C. Schroeder" To: pgsql-general@postgresql.org, Martijn van Oosterhout Subject: Re: Performance Problem Date: Fri, 13 Oct 2006 01:55:06 -0700 User-Agent: KMail/1.8.2 Cc: roopa perumalraja References: <20061013052628.7600.qmail@web50802.mail.yahoo.com> <20061013082210.GE1896@svana.org> In-Reply-To: <20061013082210.GE1896@svana.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 8bit Content-Disposition: inline Message-Id: <200610130155.06831.uwe@oss4u.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/558 X-Sequence-Number: 102084 On Friday 13 October 2006 01:22, Martijn van Oosterhout wrote: > >   1) I have a performance problem as I am trying to insert around 60 > >   million rows to a table which is partitioned. So first I copied the > >   .csv file which contains data, with COPY command to a temp table > >   which was quick. It took only 15 to 20 minutes. Now I am inserting > >   data from temp table to original table using insert into org_table > >   (select * from temp_table); which is taking more than an hour & is > >   still inserting. Is there an easy way to do this? > > Does the table you're inserting into have indexes or foreign keys? > Either of those slow down loading considerably. One commen workaround > is to drop the indexes and constraints, load the data and re-add them. Why do you COPY the data into a temporary table just to do a "insert into org_table (select * from temp_table);" ? Since you're copying ALL records anyways, why don't you just copy the data into the "org_table" directly? Also look for the "autocommit" setting. If autocommit is on, every insert is a transaction on it's own - leading to a lot of overhead. Turning autocommit off and running the inserts in batches of - say 1000 inserts per transaction - will increase speed considerably. UC -- Open Source Solutions 4U, LLC 1618 Kelly St Phone: +1 707 568 3056 Santa Rosa, CA 95401 Cell: +1 650 302 2405 United States Fax: +1 707 568 6416