aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/cluster.c10
-rw-r--r--src/backend/commands/tablecmds.c31
2 files changed, 40 insertions, 1 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 39185cc5b9f..9d22f648a84 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -735,7 +735,7 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod,
if (isNull)
reloptions = (Datum) 0;
- NewHeapCreateToastTable(OIDNewHeap, reloptions, lockmode);
+ NewHeapCreateToastTable(OIDNewHeap, reloptions, lockmode, toastid);
ReleaseSysCache(tuple);
}
@@ -1526,6 +1526,14 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
RenameRelationInternal(toastidx,
NewToastName, true, true);
+
+ /*
+ * Reset the relrewrite for the toast. The command-counter
+ * increment is required here as we are about to update
+ * the tuple that is updated as part of RenameRelationInternal.
+ */
+ CommandCounterIncrement();
+ ResetRelRewrite(newrel->rd_rel->reltoastrelid);
}
relation_close(newrel, NoLock);
}
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a03077139d5..dbee6ae199f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -3850,6 +3850,37 @@ RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bo
}
/*
+ * ResetRelRewrite - reset relrewrite
+ */
+void
+ResetRelRewrite(Oid myrelid)
+{
+ Relation relrelation; /* for RELATION relation */
+ HeapTuple reltup;
+ Form_pg_class relform;
+
+ /*
+ * Find relation's pg_class tuple.
+ */
+ relrelation = table_open(RelationRelationId, RowExclusiveLock);
+
+ reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(myrelid));
+ if (!HeapTupleIsValid(reltup)) /* shouldn't happen */
+ elog(ERROR, "cache lookup failed for relation %u", myrelid);
+ relform = (Form_pg_class) GETSTRUCT(reltup);
+
+ /*
+ * Update pg_class tuple.
+ */
+ relform->relrewrite = InvalidOid;
+
+ CatalogTupleUpdate(relrelation, &reltup->t_self, reltup);
+
+ heap_freetuple(reltup);
+ table_close(relrelation, RowExclusiveLock);
+}
+
+/*
* Disallow ALTER TABLE (and similar commands) when the current backend has
* any open reference to the target table besides the one just acquired by
* the calling command; this implies there's an open cursor or active plan.