forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf0c569d
committed
Fix memory leak in pgoutput with publication list cache
The pgoutput module caches publication names in a list and frees it uponinvalidation. However, the code forgot to free the actual publicationnames within the list elements, as publication names are pstrdup()'d inGetPublication(). This would cause memory to leak inCacheMemoryContext, bloating it over time as this context is notcleaned.This is a problem for WAL senders running for a long time, as anaccumulation of invalidation requests would bloat its cache memoryusage. A second case, where this leak is easier to see, involves abackend calling SQL functions like pg_logical_slot_{get,peek}_changes()which create a new decoding context with each execution. Morepublications create more bloat.To address this, this commit adds a new memory context within thelogical decoding context and resets it each time the publication namescache is invalidated, based on a suggestion from Amit Kapila. Thisensures that the lifespan of the publication names aligns with that ofthe logical decoding context.This solution changes PGOutputData, which is fine for HEAD but it couldcause an ABI breakage in stable branches as the structure size wouldchange, so these are left out for now.Analyzed-by: Michael Paquier, Jeff DavisAuthor: Zhijie HouReviewed-by: Michael Paquier, Masahiko Sawada, Euler TaveiraDiscussion:https://postgr.es/m/Z0khf9EVMVLOc_YY@paquier.xyz1 parent001a537 commitf0c569d
File tree
2 files changed
+11
-9
lines changed- src
- backend/replication/pgoutput
- include/replication
2 files changed
+11
-9
lines changedLines changed: 10 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
436 | 436 |
| |
437 | 437 |
| |
438 | 438 |
| |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
439 | 443 |
| |
440 | 444 |
| |
441 | 445 |
| |
| |||
1734 | 1738 |
| |
1735 | 1739 |
| |
1736 | 1740 |
| |
1737 |
| - | |
1738 |
| - | |
1739 |
| - | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
1740 | 1744 |
| |
1741 | 1745 |
| |
1742 | 1746 |
| |
| |||
2063 | 2067 |
| |
2064 | 2068 |
| |
2065 | 2069 |
| |
2066 |
| - | |
2067 |
| - | |
2068 |
| - | |
2069 |
| - | |
2070 |
| - | |
2071 |
| - | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
2072 | 2073 |
| |
2073 | 2074 |
| |
2074 | 2075 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
|
0 commit comments
Comments
(0)