Re: Curious situation - running program cannot seem to delete records.

From: btober(at)ct(dot)metrocast(dot)net
To: Andrew Edson <cheighlund(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Curious situation - running program cannot seem to delete records.
Date: 2007-02-28 15:17:41
Message-ID: 45E59D15.9070905@ct.metrocast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrew Edson wrote:
> I've been given a file to maintain, the purpose of which is to purge the database of records more than two years old. (Database setup is pg 8.1.3)
>
> The program (written in perl) enters postgres as the user 'postgres', and is supposed to select foreign-key records from all tables that link together with a table which has a delete_dt field in it, so long as the delete_dt value (timestamp with time zone) is more than two years old. It then, within a running loop, is supposed to table-by-table delete all records where the value of the key in question matches the returned value.

Why don't you use ON DELETE CASCADE foreign key constraints? Let the
data base handle all this work rather than maintaining a complicated
external Perl script which might get out if sync with the data base as
data base design changes are implemented. You don't even need Perl at
all, actually: Have cron fire a very simple shell command using psql to
invoke the delete command against the primary key table (the one with
the delete_dt field), and let the foreign key constraints take care of,
... well..., the foreign key references.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-02-28 15:30:27 Re: Post-Reboot Issue: Postmaster Not Accessible
Previous Message Rich Shepard 2007-02-28 15:13:26 Post-Reboot Issue: Postmaster Not Accessible