Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit decf3fe

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/tencent_41FEA657C206F19AB4F406BE9252A0F69C06@qq.com Discussion: https://postgr.es/m/tencent_6E296D2F7D70AFC90D83353B69187C3AA507@qq.com
1 parent 14a608a commit decf3fe

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
@@ -363,6 +363,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
363363
PGOutputData *data = (PGOutputData *) ctx->output_plugin_private;
364364
MemoryContext old;
365365
RelationSyncEntry *relentry;
366+
Relation ancestor = NULL;
366367

367368
if (!is_publishable_relation(relation))
368369
return;
@@ -404,7 +405,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
404405
if (relentry->publish_as_relid != RelationGetRelid(relation))
405406
{
406407
Assert(relation->rd_rel->relispartition);
407-
relation = RelationIdGetRelation(relentry->publish_as_relid);
408+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
409+
relation = ancestor;
408410
/* Convert tuple if needed. */
409411
if (relentry->map)
410412
tuple = execute_attr_map_tuple(tuple, relentry->map);
@@ -425,7 +427,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
425427
if (relentry->publish_as_relid != RelationGetRelid(relation))
426428
{
427429
Assert(relation->rd_rel->relispartition);
428-
relation = RelationIdGetRelation(relentry->publish_as_relid);
430+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
431+
relation = ancestor;
429432
/* Convert tuples if needed. */
430433
if (relentry->map)
431434
{
@@ -448,7 +451,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
448451
if (relentry->publish_as_relid != RelationGetRelid(relation))
449452
{
450453
Assert(relation->rd_rel->relispartition);
451-
relation = RelationIdGetRelation(relentry->publish_as_relid);
454+
ancestor = RelationIdGetRelation(relentry->publish_as_relid);
455+
relation = ancestor;
452456
/* Convert tuple if needed. */
453457
if (relentry->map)
454458
oldtuple = execute_attr_map_tuple(oldtuple, relentry->map);
@@ -465,6 +469,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
465469
Assert(false);
466470
}
467471

472+
if (RelationIsValid(ancestor))
473+
{
474+
RelationClose(ancestor);
475+
ancestor = NULL;
476+
}
477+
468478
/* Cleanup */
469479
MemoryContextSwitchTo(old);
470480
MemoryContextReset(data->context);

0 commit comments

Comments
 (0)