diff options
author | Amit Kapila <akapila@postgresql.org> | 2021-01-12 08:30:16 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2021-01-12 08:30:16 +0530 |
commit | decf3fe61ca2b707e8ac7ef996b16ace8df1d165 (patch) | |
tree | 7e6d9c768d6ef451710a34e0f7c7a4bdc8cfeaa0 | |
parent | 14a608aef41b35ed4c2599493aaafe496fec3b3c (diff) | |
download | postgresql-decf3fe61ca2b707e8ac7ef996b16ace8df1d165.tar.gz postgresql-decf3fe61ca2b707e8ac7ef996b16ace8df1d165.zip |
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
-rw-r--r-- | src/backend/replication/pgoutput/pgoutput.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 15379e31181..c5fbebf55ab 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -363,6 +363,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, PGOutputData *data = (PGOutputData *) ctx->output_plugin_private; MemoryContext old; RelationSyncEntry *relentry; + Relation ancestor = NULL; if (!is_publishable_relation(relation)) return; @@ -404,7 +405,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (relentry->publish_as_relid != RelationGetRelid(relation)) { Assert(relation->rd_rel->relispartition); - relation = RelationIdGetRelation(relentry->publish_as_relid); + ancestor = RelationIdGetRelation(relentry->publish_as_relid); + relation = ancestor; /* Convert tuple if needed. */ if (relentry->map) tuple = execute_attr_map_tuple(tuple, relentry->map); @@ -425,7 +427,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (relentry->publish_as_relid != RelationGetRelid(relation)) { Assert(relation->rd_rel->relispartition); - relation = RelationIdGetRelation(relentry->publish_as_relid); + ancestor = RelationIdGetRelation(relentry->publish_as_relid); + relation = ancestor; /* Convert tuples if needed. */ if (relentry->map) { @@ -448,7 +451,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (relentry->publish_as_relid != RelationGetRelid(relation)) { Assert(relation->rd_rel->relispartition); - relation = RelationIdGetRelation(relentry->publish_as_relid); + ancestor = RelationIdGetRelation(relentry->publish_as_relid); + relation = ancestor; /* Convert tuple if needed. */ if (relentry->map) oldtuple = execute_attr_map_tuple(oldtuple, relentry->map); @@ -465,6 +469,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Assert(false); } + if (RelationIsValid(ancestor)) + { + RelationClose(ancestor); + ancestor = NULL; + } + /* Cleanup */ MemoryContextSwitchTo(old); MemoryContextReset(data->context); |