unreferenced primary keys: garbage collection - Mailing list pgsql-sql

From Forest Wilkinson
Subject unreferenced primary keys: garbage collection
Date
Msg-id 4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com
Whole thread Raw
Responses Re: unreferenced primary keys: garbage collection  (Jan Wieck <janwieck@Yahoo.com>)
List pgsql-sql
I have a database in which five separate tables may (or may not) reference
any given row in a table of postal addresses.  I am using the primary /
foreign key support in postgres 7 to represent these references.

My problem is that, any time a reference is removed (either by deleting or
updating a row in one of the five referencing tables), no garbage
collection is being performed on the address table.  That is, when the
last reference to an address record goes away, the record is not removed
from the address table.  Over time, my database will fill up with
abandoned address records.

I suppose I could write procedural code in my client application, to check
for abandonment when a reference is removed, but that would require
examining each of the five referencing tables.  I consider this a messy
option, and I expect it would be rather inefficient.

I thought of attempting to delete the address record any time a reference
to it is removed, and relying on foreign key constraints to prevent the
deletion if it is referenced elsewhere.  However, I believe postgres will
force the entire transaction block to be rolled back in such cases, thus
nullifying all the other work done in the transaction.  This is clearly
undesirable.

Isn't there some way to tell postgres *not* to roll back my transaction if
a particular DELETE fails due to referential integrity?  Are there any
other options that might help me?

Regards,

Forest Wilkinson



pgsql-sql by date:

Previous
From: "Robert B. Easter"
Date:
Subject: Re: Trouble with subqueries
Next
From: Jan Wieck
Date:
Subject: Re: unreferenced primary keys: garbage collection