Add checks to TRUNCATE, CLUSTER, and REINDEX to prevent performing these
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Jan 2008 19:46:48 +0000 (19:46 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Jan 2008 19:46:48 +0000 (19:46 +0000)
commit6b7ff409b435a6da73f9862f20f1a9cdf6f846c4
tree92df7f04f8bd61d2a80d1e628958165fe1bbc7c8
parent37b84be370dc51242d222aa201bf2b721cc35cb1
Add checks to TRUNCATE, CLUSTER, and REINDEX to prevent performing these
operations when the current transaction has any open references to the
target relation or index (implying it has an active query using the relation).
The need for this was previously recognized in connection with ALTER TABLE,
but anything that summarily eliminates tuples or moves them around would
confuse an active scan.

While this patch does not in itself fix bug #3883 (the deadlock would happen
before the new check fires), it will discourage people from attempting the
sequence of operations that creates a deadlock risk, so it's at least a
partial response to that problem.

In passing, add a previously-missing check to REINDEX to prevent trying to
reindex another backend's temp table.  This isn't a security problem since
only a superuser would get past the schema permission checks, but if we are
testing for this in other utility commands then surely REINDEX should too.
src/backend/catalog/index.c
src/backend/commands/cluster.c
src/backend/commands/tablecmds.c
src/include/commands/tablecmds.h