summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2026-08-19 02:32:58 +0000
committerMichael Paquier2026-08-19 02:32:58 +0000
commit29b52d2b47fb8fa892695bc941d3e035164481cf (patch)
tree5a878d9415149d3f83166f593d02d706b5b88605
parent19d900358fd6f200ada6aabfa4d44d83c16a3f0a (diff)
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(). Looking at the in-core code paths building XLOG_HEAP_TRUNCATE records, no relation OIDs would be included if they do not satisfy RelationIsLogicallyLogged(). One pattern that could go through is if a table is switched to SET UNLOGGED, but that would not be reachable in practice as the decoding happens after a historical snapshot is taken, so the relation should still be valid. This is a defense-in-depth measure in practice, and we tend to be careful about how Relations are handled when sending changes to output plugins, so backpatch all the way down. Author: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com> Discussion: https://postgr.es/m/7DD65D03-3B5A-43B2-99AD-8E6AF5372BAB@gmail.com Backpatch-through: 14
-rw-r--r--src/backend/replication/logical/reorderbuffer.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e6e14c5fb02..0a84443208f 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2355,7 +2355,10 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
elog(ERROR, "could not open relation with OID %u", relid);
if (!RelationIsLogicallyLogged(relation))
+ {
+ RelationClose(relation);
continue;
+ }
relations[nrelations++] = relation;
}