aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/cache/relcache.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index c6e3dc30169..2babf525380 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3359,6 +3359,13 @@ RelationBuildLocalRelation(const char *relname,
rel->rd_rel->relam = accessmtd;
+ /*
+ * RelationInitTableAccessMethod will do syscache lookups, so we mustn't
+ * run it in CacheMemoryContext. Fortunately, the remaining steps don't
+ * require a long-lived current context.
+ */
+ MemoryContextSwitchTo(oldcxt);
+
if (relkind == RELKIND_RELATION ||
relkind == RELKIND_SEQUENCE ||
relkind == RELKIND_TOASTVALUE ||
@@ -3382,11 +3389,6 @@ RelationBuildLocalRelation(const char *relname,
*/
EOXactListAdd(rel);
- /*
- * done building relcache entry.
- */
- MemoryContextSwitchTo(oldcxt);
-
/* It's fully valid */
rel->rd_isvalid = true;