Hi, Rahila! On Thu, Mar 13, 2025 at 3:57 PM Rahila Syed <rahilasye...@gmail.com> wrote: > > Please find attached updated and rebased patches. It has the following changes > > 1. To prevent memory leaks, ensure that the latest statistics published by a > process > are freed before it exits. This can be achieved by calling dsa_free in the > before_shmem_exit callback. > 2. Add a level column to maintain consistency with the output of > pg_backend_memory_contexts.
Thank you for your work on this subject. v17-0001-Preparatory-changes-for-reporting-memory-context-sta.patch It looks like we're increasing *num_contexts twice per child memory context. First, it gets increased with a recursive MemoryContextStatsInternal() call, then by adding an ichild. I might be wrong, but I think these calculations at least deserve more comments. v17-0002-Function-to-report-memory-context-statistics.patch + if (procNumber == MyProcNumber) + { + ereport(WARNING, + errmsg("cannot return statistics for local backend"), + errhint("Use pg_backend_memory_contexts view instead.")); + PG_RETURN_NULL(); + } Is it worth it to keep this restriction? Can we fetch info about local memory context for the sake of generality? I know there have been discussions in the thread before, but the mechanism of publishing memory context stats via DSA looks quite complicated. Also, the user probably intends to inspect memory contexts when there is not a huge amount of free memory. So, failure is probable on DSA allocation. Could we do simpler? For instance, allocate some amount of static shared memory and use it as a message queue between processes. As a heavy load is not supposed to be here, I think one queue would be enough. ------ Regards, Alexander Korotkov Supabase