pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Forest Wilkinson <fspam@home.com>
To: pgsql-sql@postgresql.org
Subject: unreferenced primary keys: garbage collection
Date: Fri, 19 Jan 2001 20:54:21 -0800
Message-ID: <4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com> (raw)

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




view thread (7+ messages)  latest in thread

Message-ID: <4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com>
Permalink:  ../4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com/
Also on:    postgresql.org/message-id/4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: fspam@home.com
  Subject: Re: unreferenced primary keys: garbage collection
  In-Reply-To: <4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com>
  References: <4l5i6tcr56fkb8hob8a3bas3ce0qq53d6l@4ax.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox