From 30a53ee7a12f42181615a61e625596f6dd00014c Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 18 Aug 2026 11:37:54 +0800
Subject: [PATCH v1] Fix relcache reference leak when decoding TRUNCATE

ReorderBufferProcessTXN() opens every relation referenced by a
TRUNCATE change. When RelationIsLogicallyLogged() returns false,
it skips the relation without releasing the reference acquired
by RelationIdGetRelation().

Close the relation before continuing.

Author: Chao Li <lic@highgo.com>
---
 src/backend/replication/logical/reorderbuffer.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 6aed6346366..b34ec5f2145 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2492,7 +2492,10 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
 								elog(ERROR, "could not open relation with OID %u", relid);
 
 							if (!RelationIsLogicallyLogged(rel))
+							{
+								RelationClose(rel);
 								continue;
+							}
 
 							relations[nrelations++] = rel;
 						}
-- 
2.50.1 (Apple Git-155)

