=== Applying patches on top of PostgreSQL commit ID 4fbb46f61271f4b7f46ecad3de608fc2f4d7d80f === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Wed May 28 10:20:17 UTC 2025 On branch cf/5766 nothing to commit, working tree clean === using 'git am' to apply patch ./v3-0001-PG14-PG16-Add-guard-to-prevent-recursive-memory-context-log.patch === Applying: Add guard to prevent recursive memory context logging. Using index info to reconstruct a base tree... M src/backend/utils/mmgr/mcxt.c Falling back to patching base and 3-way merge... Auto-merging src/backend/utils/mmgr/mcxt.c CONFLICT (content): Merge conflict in src/backend/utils/mmgr/mcxt.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Add guard to prevent recursive memory context logging. When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/utils/mmgr/mcxt.c === using patch(1) to apply patch ./v3-0001-PG14-PG16-Add-guard-to-prevent-recursive-memory-context-log.patch === patching file src/backend/utils/mmgr/mcxt.c Hunk #1 FAILED at 149. Hunk #2 FAILED at 1201. 2 out of 2 hunks FAILED -- saving rejects to file src/backend/utils/mmgr/mcxt.c.rej Removing src/backend/utils/mmgr/mcxt.c.rej === using 'git apply' to apply patch ./v3-0001-PG14-PG16-Add-guard-to-prevent-recursive-memory-context-log.patch === Applied patch to 'src/backend/utils/mmgr/mcxt.c' with conflicts. U src/backend/utils/mmgr/mcxt.c diff --cc src/backend/utils/mmgr/mcxt.c index 15fa4d0a55e,30286a3ff33..00000000000 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@@ -157,10 -149,12 +157,16 @@@ MemoryContext CurTransactionContext = N /* This is a transient link to the active portal's memory context: */ MemoryContext PortalContext = NULL; ++<<<<<<< ours +static void MemoryContextDeleteOnly(MemoryContext context); ++======= + /* Is memory context logging currently in progress? */ + static bool LogMemoryContextInProgress = false; + ++>>>>>>> theirs static void MemoryContextCallResetCallbacks(MemoryContext context); static void MemoryContextStatsInternal(MemoryContext context, int level, - bool print, int max_children, + int max_level, int max_children, MemoryContextCounters *totals, bool print_to_stderr); static void MemoryContextStatsPrint(MemoryContext context, void *passthru, @@@ -1295,26 -1204,45 +1301,60 @@@ ProcessLogMemoryContextInterrupt(void LogMemoryContextPending = false; /* - * Use LOG_SERVER_ONLY to prevent this message from being sent to the - * connected client. + * Exit immediately if memory context logging is already in progress. This + * prevents recursive calls, which could occur if logging is requested + * repeatedly and rapidly, potentially leading to infinite recursion and a + * crash. */ - ereport(LOG_SERVER_ONLY, - (errhidestmt(true), - errhidecontext(true), - errmsg("logging memory contexts of PID %d", MyProcPid))); + if (LogMemoryContextInProgress) + return; + LogMemoryContextInProgress = true; ++<<<<<<< ours + /* + * When a backend process is consuming huge memory, logging all its memory + * contexts might overrun available disk space. To prevent this, we limit + * the depth of the hierarchy, as well as the number of child contexts to + * log per parent to 100. + * + * As with MemoryContextStats(), we suppose that practical cases where the + * dump gets long will typically be huge numbers of siblings under the + * same parent context; while the additional debugging value from seeing + * details about individual siblings beyond 100 will not be large. + */ + MemoryContextStatsDetail(TopMemoryContext, 100, 100, false); ++======= + PG_TRY(); + { + /* + * Use LOG_SERVER_ONLY to prevent this message from being sent to the + * connected client. + */ + ereport(LOG_SERVER_ONLY, + (errhidestmt(true), + errhidecontext(true), + errmsg("logging memory contexts of PID %d", MyProcPid))); + + /* + * When a backend process is consuming huge memory, logging all its + * memory contexts might overrun available disk space. To prevent + * this, we limit the number of child contexts to log per parent to + * 100. + * + * As with MemoryContextStats(), we suppose that practical cases where + * the dump gets long will typically be huge numbers of siblings under + * the same parent context; while the additional debugging value from + * seeing details about individual siblings beyond 100 will not be + * large. + */ + MemoryContextStatsDetail(TopMemoryContext, 100, false); + } + PG_FINALLY(); + { + LogMemoryContextInProgress = false; + } + PG_END_TRY(); ++>>>>>>> theirs } void *