aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/cluster.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-01-30 19:46:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-01-30 19:46:48 +0000
commit0688d84041f7963a2a00468c53aec7bb6051ef5c (patch)
tree51e38fe31f476f4003c44f3b23f5253c33f0b56a /src/backend/commands/cluster.c
parent47df4f668826c0646ae30d37971e4ff15e77b3e3 (diff)
downloadpostgresql-0688d84041f7963a2a00468c53aec7bb6051ef5c.tar.gz
postgresql-0688d84041f7963a2a00468c53aec7bb6051ef5c.zip
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.
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r--src/backend/commands/cluster.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index a2a94f1e826..7a9ad8d19a8 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.168 2008/01/15 21:20:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.169 2008/01/30 19:46:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -30,6 +30,7 @@
#include "catalog/namespace.h"
#include "catalog/toasting.h"
#include "commands/cluster.h"
+#include "commands/tablecmds.h"
#include "commands/trigger.h"
#include "commands/vacuum.h"
#include "miscadmin.h"
@@ -459,15 +460,10 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
errmsg("cannot cluster temporary tables of other sessions")));
/*
- * Also check for pending AFTER trigger events on the relation. We can't
- * just leave those be, since they will try to fetch tuples that the
- * CLUSTER has moved to new TIDs.
+ * Also check for active uses of the relation in the current transaction,
+ * including open scans and pending AFTER trigger events.
*/
- if (AfterTriggerPendingOnRel(RelationGetRelid(OldHeap)))
- ereport(ERROR,
- (errcode(ERRCODE_OBJECT_IN_USE),
- errmsg("cannot cluster table \"%s\" because it has pending trigger events",
- RelationGetRelationName(OldHeap))));
+ CheckTableNotInUse(OldHeap, "CLUSTER");
/* Drop relcache refcnt on OldIndex, but keep lock */
index_close(OldIndex, NoLock);