pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Uwe C. Schroeder <uwe@oss4u.com>
To: pgsql-general@postgresql.org
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: roopa perumalraja <roopabenzer@yahoo.com>
Subject: Re: Performance Problem
Date: Fri, 13 Oct 2006 01:55:06 -0700
Message-ID: <200610130155.06831.uwe@oss4u.com> (raw)
In-Reply-To: <20061013082210.GE1896@svana.org>
References: <20061013052628.7600.qmail@web50802.mail.yahoo.com>
	<20061013082210.GE1896@svana.org>

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



view thread (47+ messages)  latest in thread

Message-ID: <200610130155.06831.uwe@oss4u.com>
Permalink:  ../200610130155.06831.uwe@oss4u.com/
Also on:    postgresql.org/message-id/200610130155.06831.uwe@oss4u.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: uwe@oss4u.com, kleptog@svana.org, roopabenzer@yahoo.com
  Subject: Re: Performance Problem
  In-Reply-To: <200610130155.06831.uwe@oss4u.com>
  References: <20061013052628.7600.qmail@web50802.mail.yahoo.com> <20061013082210.GE1896@svana.org> <200610130155.06831.uwe@oss4u.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox