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

Commit ea792bf

Browse files
committed
Fix memory leak in pgoutput for the WAL sender
RelationSyncCache, the hash table in charge of tracking the relation schemas sent through pgoutput, was forgetting to free the TupleDesc associated to the two slots used to store the new and old tuples, causing some memory to be leaked each time a relation is invalidated when the slots of an existing relation entry are cleaned up. This is rather hard to notice as the bloat is pretty minimal, but a long-running WAL sender would be in trouble over time depending on the workload. sysbench has proved to be pretty good at showing the problem, coupled with some memory monitoring of the WAL sender. Issue introduced in 52e4f0c, that has added row filters for tables logically replicated. Author: Boyu Yang Reviewed-by: Michael Paquier, Hou Zhijie Discussion: https://postgr.es/m/DM3PR84MB3442E14B340E553313B5C816E3252@DM3PR84MB3442.NAMPRD84.PROD.OUTLOOK.COM Backpatch-through: 15
1 parent f95da9f commit ea792bf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/backend/replication/pgoutput/pgoutput.c

+24
Original file line numberDiff line numberDiff line change
@@ -2095,10 +2095,34 @@ get_rel_sync_entry(PGOutputData *data, Relation relation)
20952095
* Tuple slots cleanups. (Will be rebuilt later if needed).
20962096
*/
20972097
if (entry->old_slot)
2098+
{
2099+
TupleDesc desc = entry->old_slot->tts_tupleDescriptor;
2100+
2101+
Assert(desc->tdrefcount == -1);
2102+
20982103
ExecDropSingleTupleTableSlot(entry->old_slot);
2104+
2105+
/*
2106+
* ExecDropSingleTupleTableSlot() would not free the TupleDesc, so
2107+
* do it now to avoid any leaks.
2108+
*/
2109+
FreeTupleDesc(desc);
2110+
}
20992111
if (entry->new_slot)
2112+
{
2113+
TupleDesc desc = entry->new_slot->tts_tupleDescriptor;
2114+
2115+
Assert(desc->tdrefcount == -1);
2116+
21002117
ExecDropSingleTupleTableSlot(entry->new_slot);
21012118

2119+
/*
2120+
* ExecDropSingleTupleTableSlot() would not free the TupleDesc, so
2121+
* do it now to avoid any leaks.
2122+
*/
2123+
FreeTupleDesc(desc);
2124+
}
2125+
21022126
entry->old_slot = NULL;
21032127
entry->new_slot = NULL;
21042128

0 commit comments

Comments
 (0)