Re: Enhancing Memory Context Statistics Reporting

torikoshia <torikoshia@oss.nttdata.com>

From: torikoshia <torikoshia@oss.nttdata.com>
To: Rahila Syed <rahilasyed90@gmail.com>
Cc: Tomas Vondra <tomas@vondra.me>, Alvaro Herrera <alvherre@alvh.no-ip.org>, Michael Paquier <michael@paquier.xyz>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-12-16T12:51:53Z
Lists: pgsql-hackers
Hi,

Thanks for updating the patch and here are some comments:

'path' column of pg_get_process_memory_contexts() begins with 0, but 
that column of pg_backend_memory_contexts view begins with 1:

   =# select path FROM pg_get_process_memory_contexts('20271', false);
   path
   -------
    {0}
    {0,1}
    {0,2}
    ..

=# select path from pg_backend_memory_contexts;
    path
   -------
    {1}
    {1,2}
    {1,3}
    ..asdf asdf

Would it be better to begin with 1 to make them consistent?


pg_log_backend_memory_contexts() does not allow non-superusers to 
execute by default since it can peek at other session information.
pg_get_process_memory_contexts() does not have this restriction, but 
wouldn't it be necessary?


When the target pid is the local backend, the HINT suggests using 
pg_get_backend_memory_contexts(), but this function is not described in 
the manual.
How about suggesting pg_backend_memory_contexts view instead?

   =# select pg_get_process_memory_contexts('27041', false);
   WARNING:  cannot return statistics for local backend
   HINT:  Use pg_get_backend_memory_contexts instead


There are no explanations about 'num_agg_contexts', but I thought the 
explanation like below would be useful.

> I have added this information as a column named "num_agg_contexts", 
> which indicates
> the number of contexts whose statistics have been aggregated/added for 
> a particular output.

git apply caused some warnings:

$ git apply 
v7-Function-to-report-memory-context-stats-of-any-backe.patch
v7-Function-to-report-memory-context-stats-of-any-backe.patch:71: space 
before tab in indent.
         Requests to return the memory contexts of the backend with the
v7-Function-to-report-memory-context-stats-of-any-backe.patch:72: space 
before tab in indent.
         specified process ID.  This function can send the request to
v7-Function-to-report-memory-context-stats-of-any-backe.patch:ldmv: 
space before tab in indent.
         both the backends and auxiliary processes. After receiving the 
memory
v7-Function-to-report-memory-context-stats-of-any-backe.patch:74: space 
before tab in indent.
         contexts from the process, it returns the result as one row per
v7-Function-to-report-memory-context-stats-of-any-backe.patch:75: space 
before tab in indent.
         context. When get_summary is true, memory contexts at level 0


-- 
Regards,

--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Cross-check lists of built-in LWLock tranches.

  2. Convert strncpy to strlcpy

  3. Typo and doc fixups for memory context reporting

  4. Add missing string terminator

  5. Rename argument in pg_get_process_memory_contexts().

  6. Add function to get memory context stats for processes