Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: bulk insert performance problem


  • From: Chris <dmagick(at)gmail(dot)com>
  • To: Christian Bourque <christian(dot)bourque(at)gmail(dot)com>
  • Cc: pgsql-performance(at)postgresql(dot)org
  • Subject: Re: bulk insert performance problem
  • Date: Tue, 08 Apr 2008 13:32:56 +1000
  • Message-id: <47FAE768(dot)80200(at)gmail(dot)com>

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/



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group