Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id C316B2E005D for ; Tue, 8 Apr 2008 00:35:05 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57431-07 for ; Tue, 8 Apr 2008 00:35:03 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.174]) by developer.postgresql.org (Postfix) with ESMTP id 203DA2E0048 for ; Tue, 8 Apr 2008 00:35:02 -0300 (ADT) Received: by wf-out-1314.google.com with SMTP id 28so1729067wff.28 for ; Mon, 07 Apr 2008 20:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=17bUIoHz2jEH/TXERK4TWc2nfJ3VisOSohkHbaA/gI0=; b=g+katIW1PgiCovhXjttqaCFvoOlP5tHe0qozMivUphb8Z6yEBcgorUEHc0hpx7KXkAmKp1SmqzQ8sMPVWbWiky6aF6Snff69GtqQVdE5PwIEo0W92Mq3KK/jgBw00fETOeSSn/caSVCpdAd+mxlFuosWYObgnNztI7iGOCfO7/8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=MZMq00xAksTWTI+M7+APKuYJ9o4thAucDx90uuUlujN0PlO/kz3FGw/uIkMb9MNaATK2dgXYEJFLeoDXc0+Mq9DRplmhx7WrmJE2mRXicU6EqFYGPSAk9ljfro6C4cJbe1psIS8+GQeJkcNhQkJe51/QPNqx0uef9Jb1LZknwHk= Received: by 10.142.83.4 with SMTP id g4mr2956941wfb.103.1207625702384; Mon, 07 Apr 2008 20:35:02 -0700 (PDT) Received: from ?10.1.1.5? ( [203.206.174.100]) by mx.google.com with ESMTPS id 20sm637234wfi.14.2008.04.07.20.34.58 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Apr 2008 20:34:59 -0700 (PDT) Message-ID: <47FAE768.80200@gmail.com> Date: Tue, 08 Apr 2008 13:32:56 +1000 From: Chris User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Christian Bourque CC: pgsql-performance@postgresql.org Subject: Re: bulk insert performance problem References: <47FAE418.3000406@postnewspapers.com.au> In-Reply-To: <47FAE418.3000406@postnewspapers.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/79 X-Sequence-Number: 29572 Craig Ringer wrote: > Christian Bourque wrote: >> Hi, >> >> I have a performance problem with a script that does massive bulk >> insert in 6 tables. When the script starts the performance is really >> good but will degrade minute after minute and take almost a day to >> finish! >> > Would I be correct in guessing that there are foreign key relationships > between those tables, and that there are significant numbers of indexes > in use? > > The foreign key checking costs will go up as the tables grow, and AFAIK > the indexes get a bit more expensive to maintain too. > > If possible you should probably drop your foreign key relationships and > drop your indexes, insert your data, then re-create the indexes and > foreign keys. The foreign keys will be rechecked when you recreate them, > and it's *vastly* faster to do it that way. Similarly, building an index > from scratch is quite a bit faster than progressively adding to it. Of > course, dropping the indices is only useful if you aren't querying the > tables as you build them. If you are, add "analyze" commands through the import, eg every 10,000 rows. Then your checks should be a bit faster. The other suggestion would be to do block commits: begin; do stuff for 5000 rows; commit; repeat until finished. -- Postgresql & php tutorials http://www.designmagick.com/