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 <[email protected]>
Reviewed-by: Xuneng Zhou <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4a710d68871cd9bbdcc57b244dbbeeca08de7735

Modified Files
--------------
src/backend/replication/logical/reorderbuffer.c | 3 +++
1 file changed, 3 insertions(+)

Reply via email to