From a33ad3b07ee321e0c3ab4ab1c40cbade6f71b794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Thu, 19 Mar 2026 19:48:34 +0100 Subject: [PATCH v44 04/10] Fix crash caused by involuntary decoding of unrelated relations Author: Srinath Reddy Sadipiralla --- src/backend/commands/cluster.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index edb515d4b3e..b4acaeb6b93 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -2666,6 +2666,21 @@ repack_setup_logical_decoding(Oid relid) */ Assert(!ctx->fast_forward); + /* Avoid logical decoding of other relations. */ + rel = table_open(relid, AccessShareLock); + repacked_rel_locator = rel->rd_locator; + toastrelid = rel->rd_rel->reltoastrelid; + if (OidIsValid(toastrelid)) + { + Relation toastrel; + + /* Avoid logical decoding of other TOAST relations. */ + toastrel = table_open(toastrelid, AccessShareLock); + repacked_rel_toast_locator = toastrel->rd_locator; + table_close(toastrel, AccessShareLock); + } + table_close(rel, AccessShareLock); + DecodingContextFindStartpoint(ctx); /* @@ -2702,21 +2717,6 @@ repack_setup_logical_decoding(Oid relid) "REPACK - change", ALLOCSET_DEFAULT_SIZES); - /* Avoid logical decoding of other relations. */ - rel = table_open(relid, AccessShareLock); - repacked_rel_locator = rel->rd_locator; - toastrelid = rel->rd_rel->reltoastrelid; - if (OidIsValid(toastrelid)) - { - Relation toastrel; - - /* Avoid logical decoding of other TOAST relations. */ - toastrel = table_open(toastrelid, AccessShareLock); - repacked_rel_toast_locator = toastrel->rd_locator; - table_close(toastrel, AccessShareLock); - } - table_close(rel, AccessShareLock); - /* The file will be set as soon as we have it opened. */ dstate->file = NULL; -- 2.47.3