Re: How to efficiently duplicate a whole schema?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sebastien Lemieux <slemieux(at)elitra(dot)com>
Cc: Postgresql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: How to efficiently duplicate a whole schema?
Date: 2003-08-06 19:13:49
Message-ID: 7235.1060197229@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Sebastien Lemieux <slemieux(at)elitra(dot)com> writes:
> All the time is taken at the commit of both transaction.

Sounds like the culprit is foreign-key checks.

One obvious question is whether you have your foreign keys set up
efficiently in the first place. As a rule, the referenced and
referencing columns should have identical datatypes and both should
be indexed. (PG will often let you create foreign key constraints
that don't meet these rules ... but performance will suffer.)

Also, what procedure are you using to delete all the old data? What
I'd recommend is
ANALYZE table;
TRUNCATE table;
INSERT new data;
The idea here is to make sure that the planner's statistics reflect the
"full" state of the table, not the "empty" state. Otherwise it may pick
plans for the foreign key checks that are optimized for small tables.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2003-08-06 19:29:23 Re: How to efficiently duplicate a whole schema?
Previous Message Nick Fankhauser 2003-08-06 19:09:48 Re: How to efficiently duplicate a whole schema?