Search Postgresql Archives

Is the "ACCESS EXCLUSIVE" lock for TRUNCATE really necessary?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux