From: | "Florian G(dot) Pflug" <fgp(at)phlo(dot)org> |
---|---|
To: | Postgresql-General <pgsql-general(at)postgresql(dot)org> |
Subject: | Is the "ACCESS EXCLUSIVE" lock for TRUNCATE really necessary? |
Date: | 2006-03-07 00:54:01 |
Message-ID: | 440CD9A9.50802@phlo.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
I know that TRUNCATE needs to acquire an ACCESS EXCLUSIVE lock,
because it will remove the datafile on commit, and needs to ensure
that noone will be using it anymore by then. For a lot of applications
(at least mine) this is imposes problems. I'd like to use TRUNCATE
in a few places, not only to "clean out" the table, but also to prevent
others from inserting while I'm deleting everything (Think a cache table -
if I clear the cache, I don't want concurrent transactions to be able
to insert - but readers are not a problem, they still see the database
in their "old state", so seeing the cache in the "old state" is correct).
Now, I was thinking if TRUNCATE couldn't just let relfilenode in
pg_class point to a new datafile, and leave the old one in place.
TRUNCATE would still need a lock that prevents any write-access to
the table, but it wouldn't need to lock-out readers too.
VACUUM could then remove datafiles when it purges a record from pg_class.
I'm asking mainly out of curiosity - I though about this for a while now,
and couldn't come up with a reason why this wouldn't be possible.
greetings, Florian Pflug
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-03-07 01:28:25 | Re: Is the "ACCESS EXCLUSIVE" lock for TRUNCATE really necessary? |
Previous Message | Michael Trausch | 2006-03-07 00:06:29 | Re: Syntax error, but where? |