Skip to content

Commit 044aa9e

Browse files
author
Amit Kapila
committed
Fix relation descriptor leak.
We missed closing the relation descriptor while sending changes via the root of partitioned relations during logical replication. Author: Amit Langote and Mark Zhao Reviewed-by: Amit Kapila and Ashutosh Bapat Backpatch-through: 13, where it was introduced Discussion: https://postgr.es/m/[email protected] Discussion: https://postgr.es/m/[email protected]
1 parent d6ad34f commit 044aa9e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backend/replication/pgoutput/pgoutput.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
502502
MemoryContext old;
503503
RelationSyncEntry *relentry;
504504
TransactionId xid = InvalidTransactionId;
505+
Relation ancestor = NULL;
505506

506507
if (!is_publishable_relation(relation))
507508
return;
@@ -552,7 +553,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
552553
if (relentry->publish_as_relid != RelationGetRelid(relation))
553554
{
554555
Assert(relation->rd_rel->relispartition);
555-
relation = RelationIdGetRelation(relentry->publish_as_relid);
556+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
557+
relation = ancestor;
556558
/* Convert tuple if needed. */
557559
if (relentry->map)
558560
tuple = execute_attr_map_tuple(tuple, relentry->map);
@@ -574,7 +576,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
574576
if (relentry->publish_as_relid != RelationGetRelid(relation))
575577
{
576578
Assert(relation->rd_rel->relispartition);
577-
relation = RelationIdGetRelation(relentry->publish_as_relid);
579+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
580+
relation = ancestor;
578581
/* Convert tuples if needed. */
579582
if (relentry->map)
580583
{
@@ -598,7 +601,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
598601
if (relentry->publish_as_relid != RelationGetRelid(relation))
599602
{
600603
Assert(relation->rd_rel->relispartition);
601-
relation = RelationIdGetRelation(relentry->publish_as_relid);
604+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
605+
relation = ancestor;
602606
/* Convert tuple if needed. */
603607
if (relentry->map)
604608
oldtuple = execute_attr_map_tuple(oldtuple, relentry->map);
@@ -616,6 +620,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
616620
Assert(false);
617621
}
618622

623+
if (RelationIsValid(ancestor))
624+
{
625+
RelationClose(ancestor);
626+
ancestor = NULL;
627+
}
628+
619629
/* Cleanup */
620630
MemoryContextSwitchTo(old);
621631
MemoryContextReset(data->context);

0 commit comments

Comments
 (0)