postgresql/src/backend
Michael Paquier 4d45e7490c Fix memory leak in pgoutput with publication list cache
The pgoutput module caches publication names in a list and frees it upon
invalidation.  However, the code forgot to free the actual publication
names within the list elements, as publication names are pstrdup()'d in
GetPublication().  This would cause memory to leak in
CacheMemoryContext, bloating it over time as this context is not
cleaned.

This is a problem for WAL senders running for a long time, as an
accumulation of invalidation requests would bloat its cache memory
usage.  A second case, where this leak is easier to see, involves a
backend calling SQL functions like pg_logical_slot_{get,peek}_changes()
which create a new decoding context with each execution.  More
publications create more bloat.

To address this, this commit adds a new memory context within the
logical decoding context and resets it each time the publication names
cache is invalidated, based on a suggestion from Amit Kapila.  This
ensures that the lifespan of the publication names aligns with that of
the logical decoding context.

Contrary to the HEAD-only commit f0c569d715 that has changed
PGOutputData to track this new child memory context, the context is
tracked with a static variable whose state is reset with a MemoryContext
reset callback attached to PGOutputData->context, so as ABI
compatibility is preserved in stable branches.  This approach is based
on an suggestion from Amit Kapila.

Analyzed-by: Michael Paquier, Jeff Davis
Author: Masahiko Sawada
Reviewed-by: Amit Kapila, Michael Paquier, Euler Taveira, Hou Zhijie
Discussion: https://postgr.es/m/Z0khf9EVMVLOc_YY@paquier.xyz
Backpatch-through: 13
2024-12-23 12:48:08 +09:00
..
access Revert "Handle better implicit transaction state of pipeline mode" 2024-11-28 09:43:22 +09:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Skip .DS_Store files in server side utils 2024-02-13 13:47:12 +01:00
bootstrap Fix CREATE INDEX progress reporting for multi-level partitioning. 2023-03-25 15:34:03 -04:00
catalog Fix corruption when relation truncation fails. 2024-12-20 23:57:26 +13:00
commands Fix comments of GUC hooks for timezone_abbreviations 2024-12-10 13:02:27 +09:00
executor Fix Assert failure in WITH RECURSIVE UNION queries 2024-12-19 13:12:41 +13:00
foreign Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:28 -07:00
jit Fix NULLIF()'s handling of read-write expanded objects. 2024-11-25 18:09:10 -05:00
lib Accommodate very large dshash tables. 2024-12-17 15:24:45 -06:00
libpq Fix regression in TLS session ticket disabling 2024-08-19 12:55:11 +02:00
main Fix elog(FATAL) before PostmasterMain() or just after fork(). 2024-12-10 13:52:02 -08:00
nodes Use a safer outfuncs/readfuncs representation for BitStrings. 2024-02-13 12:18:25 -05:00
optimizer Avoid mislabeling of lateral references, redux. 2024-11-30 12:42:20 -05:00
parser Fix typo in comment of transformJsonAggConstructor() 2024-10-16 20:36:32 +09:00
partitioning Fix creation of partition descriptor during concurrent detach+drop 2024-08-12 18:17:56 -04:00
po Translation updates 2024-11-11 13:53:52 +01:00
port Close socket in case of errors in setting non-blocking 2024-01-17 11:24:11 +01:00
postmaster Fix elog(FATAL) before PostmasterMain() or just after fork(). 2024-12-10 13:52:02 -08:00
regex Avoid assertion due to disconnected NFA sub-graphs in regex parsing. 2024-11-15 18:23:38 -05:00
replication Fix memory leak in pgoutput with publication list cache 2024-12-23 12:48:08 +09:00
rewrite Ensure cached plans are correctly marked as dependent on role. 2024-11-11 09:00:00 -06:00
snowball Fix the install rule for snowball_create.sql. 2023-05-23 11:15:57 -04:00
statistics Fix incorrectly reported stats kind in "can't happen" ERROR 2024-03-05 16:17:53 +13:00
storage Fix corruption when relation truncation fails. 2024-12-20 23:57:26 +13:00
tcop Simplify executor's determination of whether to use parallelism. 2024-12-09 14:38:19 -05:00
tsearch Limit to_tsvector_byid's initial array allocation to something sane. 2023-09-25 11:50:28 -04:00
utils Update TransactionXmin when MyProc->xmin is updated 2024-12-21 23:42:55 +02:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make headerscheck 2024-04-27 11:38:41 +07:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Add missing gettext triggers 2023-05-10 13:51:51 +02:00