Re: Enhancing Memory Context Statistics Reporting
Daniel Gustafsson <daniel@yesql.se>
From: Daniel Gustafsson <daniel@yesql.se>
To: Rahila Syed <rahilasyed90@gmail.com>
Cc: torikoshia <torikoshia@oss.nttdata.com>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-12T13:31:38Z
Lists: pgsql-hackers
> On 9 Jan 2026, at 12:22, Rahila Syed <rahilasyed90@gmail.com> wrote: > After further discussion and reviewing Robert's email[1] on this topic, a safer solution > is to avoid running ProcessGetMemoryContextInterrupt during an aborted transaction. > This should help prevent additional errors when the transaction is already in error handling > state. Also, reporting memory context statistics from an aborting transaction won't > be very useful as some of that memory usage won't be valid after abort completes. +1, I think was the right call to make. > Attached is the updated patch that addresses this. A few small comments on v47: +static const char *ContextTypeToString(NodeTag type); I think context_type_to_string() would be a better name on this internal function to model it closer to the existing int_list_to_array(). Personally I would also place it before its first use to avoid the prototype, but that's personal preference. +static void +memstats_dsa_cleanup(char *key) This function warrants a documentation comment describing when it should be used safely. + memstats_dsa_cleanup(key); + memstats_client_key_reset(procNumber); + ConditionVariableCancelSleep(); + PG_RETURN_NULL(); I think we should notify the user in these two timeout cases, why not adding an ereport(NOTICE, "request for memory context statistics timed out")); or something with a better wording than that. + Size sz = 0; + Size TotalProcs = 0; + + TotalProcs = add_size(TotalProcs, NUM_AUXILIARY_PROCS); + TotalProcs = add_size(TotalProcs, MaxBackends); + sz = add_size(sz, mul_size(TotalProcs, sizeof(int))); + + return sz As we discussed off-list, the call to add_size() call can be omitted as it won't affect the calculation. +# Copyright (c) 2025, PostgreSQL Global Development Group Here, and possibly elsewhere, it should say 2026 instead I think. -- Daniel Gustafsson
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Cross-check lists of built-in LWLock tranches.
- 2047ad068139 19 (unreleased) cited
-
Convert strncpy to strlcpy
- 45e7e8ca9e93 18.0 landed
-
Typo and doc fixups for memory context reporting
- f8c115a6cb65 18.0 landed
-
Add missing string terminator
- d2a1ed1727a8 18.0 landed
-
Rename argument in pg_get_process_memory_contexts().
- c57971034e69 18.0 landed
-
Add function to get memory context stats for processes
- 042a66291b04 18.0 landed