Re: Creating a function for exposing memory usage of backend process
Kasahara Tatsuhito <kasahara.tatsuhito@gmail.com>
From: Kasahara Tatsuhito <kasahara.tatsuhito@gmail.com>
To: Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: torikoshia <torikoshia@oss.nttdata.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>, robertmhaas@gmail.com
Date: 2020-06-26T05:53:00Z
Lists: pgsql-hackers
Hi ! On Thu, Jun 18, 2020 at 12:56 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote: > Agreed. The feature to view how local memory contexts are used in > each process is very useful! +1 > > =# SELECT * FROM pg_stat_get_backend_memory_context(PID); > > I'm afraid that this interface is not convenient when we want to monitor > the usages of local memory contexts for all the processes. For example, > I'd like to monitor how much memory is totally used to store prepared > statements information. For that purpose, I wonder if it's more convenient > to provide the view displaying the memory context usages for > all the processes. How about separating a function that examines memory consumption trends for all processes and a function that examines memory consumption for a particular phase of a particular process? For the former, as Fujii said, the function shows the output limited information for each context type. All processes calculation and output the information at idle status. I think the latter is useful for debugging and other purposes. For example, imagine preparing a function for registration like the following. =# SELECT pg_stat_get_backend_memory_context_regist (pid, context, max_children, calc_point) pid: A target process context: The top level of the context of interest max_children: Maximum number of output for the target context's children (similar to MemoryContextStatsInternal()'s max_children) calc_point: Single or multiple position(s) to calculate and output context information (Existing hooks such as planner_hook, executor_start, etc.. could be used. ) This function informs the target PID to output the information of the specified context at the specified calc_point. When the target PID process reaches the calc_point, it calculates and output the context information one time to a file or DSM. (Currently PostgreSQL has no formal ways of externally modifying the parameters of a particular process, so it may need to be implemented...) Sometimes I want to know the memory usage in the planning phase or others with a query_string and/or plan_tree that before target process move to the idle status. So it would be nice to retrieve memory usage at some arbitrary point in time ! Regards, -- Tatsuhito Kasahara kasahara.tatsuhito _at_ gmail.com
Commits
-
Add regression test for pg_backend_memory_contexts.
- adc8fc6167aa 14.0 landed
-
Move codes for pg_backend_memory_contexts from mmgr/mcxt.c to adt/mcxtfuncs.c.
- 50db5964ee33 14.0 landed
-
Prevent non-superusers from reading pg_backend_memory_contexts, by default.
- 29dd6d8bc631 14.0 landed
-
Add pg_backend_memory_contexts system view.
- 3e98c0bafb28 14.0 landed
-
Fix yet another issue with step generation in partition pruning.
- 199cec977950 14.0 cited