Batch Insert Performance - Mailing list pgsql-general

From Greg Stark
Subject Batch Insert Performance
Date
Msg-id 87ptry3knr.fsf@stark.dyndns.tv
Whole thread Raw
Responses Re: Batch Insert Performance
List pgsql-general
I'm trying to seed a database and I'm surprised by how slow it is. I'm doing a
query like:

 INSERT INTO source_other_xref (source_id, other_id) (
   SELECT source_id,1+trunc(1000*random())
     FROM source_table
   );

where source_table has 271,000 records. Table source_other_xref has two
columns both of which are foreign key references, one to source_table and the
other to another table.

It's been running for hours and hours.

The machine doesn't seem to be thrashing its disk writing or reading much. It
seems to be completely cpu-bound.

I'm thinking it's mostly wasting time checking the foreign key constraint. Is
there any equivalent to Oracle's ability to "disable" a constraint and then
reenable it later?

Even with the foreign key constraints I wouldn't have expected inserting 200k
records to take this long.

--
greg

pgsql-general by date:

Previous
From: Greg Stark
Date:
Subject: Re: Regarding select distinct ...query
Next
From: "Ian Harding"
Date:
Subject: Re: Regarding select distinct ...query