Re: BUG #5779: Large INSERT transaction with FOREIGN KEY constraints exhausts available RAM - Mailing list pgsql-bugs

From Robert Haas
Subject Re: BUG #5779: Large INSERT transaction with FOREIGN KEY constraints exhausts available RAM
Date
Msg-id AANLkTi=51_6R2Smdit3a-sxGt2_4iFreSeYtkgB22N4b@mail.gmail.com
Whole thread Raw
In response to BUG #5779: Large INSERT transaction with FOREIGN KEY constraints exhausts available RAM  ("Michel Alexandre Salim" <michel.salim@cs.fau.de>)
List pgsql-bugs
On Wed, Dec 1, 2010 at 3:09 AM, Michel Alexandre Salim
<michel.salim@cs.fau.de> wrote:
> I tried changing the fkey constraints to DEFERRABLE hoping that that would
> consume less RAM, but the same result occurs. Why should the memory usage
> pattern be different when integrity checks are done as part of the
> transaction (even when pushed back to the end), and in a separate
> transaction?

I'm just guessing here, but it may be that the trigger queue is what's
filling up all the memory.  I'm guessing that a trigger event is
getting queued for each row you INSERT.  But when you add the foreign
key later, it does a bulk validation of the entire table instead of
validating each individual row.

If that really is what's going on here, it's a known shortcoming of
the existing implementation which, unfortunately, no one has gotten
around to fixing (partly because it's not entirely obvious what the
design should be).

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: BUG #5776: Unable to create view with parameter in PL/pgsql
Next
From: Robert Haas
Date:
Subject: Re: memory leak in xml2 contrib module