Re: enhance pg_log_backend_memory_contexts() to log memory contexts of auxiliary processes

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: enhance pg_log_backend_memory_contexts() to log memory contexts of auxiliary processes
Date: 2022-01-07 15:49:10
Message-ID: c53b64cc-5f76-32e5-47e3-c551701e53c6@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2021/11/29 11:44, vignesh C wrote:
> Thanks for the updated patch. The patch applies neatly, make
> check-world passes and the documentation looks good. I did not find
> any issues with the v6 patch, I'm marking the patch as Ready for
> Committer.

I started reading the patch.

+CREATE FUNCTION memcxt_get_proc_pid(text)
+ RETURNS int
+ LANGUAGE SQL
+ AS 'SELECT pid FROM pg_stat_activity WHERE backend_type = $1';
+
+SELECT pg_log_backend_memory_contexts(memcxt_get_proc_pid('checkpointer'));
+
+DROP FUNCTION memcxt_get_proc_pid(text);

Why is memcxt_get_proc_pid() still necessary? ISTM that we can just replace the above with the following query, instead.

SELECT pg_log_backend_memory_contexts(pid) FROM pg_stat_activity WHERE backend_type = 'checkpointer'

- Requests to log the memory contexts of the backend with the
- specified process ID. These memory contexts will be logged at
- <literal>LOG</literal> message level. They will appear in
- the server log based on the log configuration set
- (See <xref linkend="runtime-config-logging"/> for more information),
- but will not be sent to the client regardless of
+ Requests to log memory contexts of the <glossterm linkend="glossary-backend">backend</glossterm>
+ or the <glossterm linkend="glossary-wal-sender">WAL sender</glossterm> or
+ the <glossterm linkend="glossary-auxiliary-proc">auxiliary process</glossterm>
+ with the specified process ID. This function cannot request
+ <glossterm linkend="glossary-postmaster">postmaster process</glossterm> or
+ <glossterm linkend="glossary-logger">logger</glossterm> or
+ <glossterm linkend="glossary-stats-collector">statistics collector</glossterm>
+ (all other <glossterm linkend="glossary-auxiliary-proc">auxiliary processes</glossterm>

ISTM that you're trying to list all possible processes that pg_log_backend_memory_contexts() can handle. But why didn't you list autovacuum worker (while other special backend, WAL sender, is picked up) and background worker like logical replication launcher? Because the term "backend" implicitly includes those processes? If so, why did you pick up WAL sender separately?

I'm tempted to replace these descriptions as follows. Because the following looks simpler and easier to read and understand, to me.

----------------------
Requests to log the memory contexts of the process with the specified process ID. Possible processes that this function can send the request to are: backend, WAL sender, autovacuum worker, auxiliary processes except logger and stats collector, and background workers.
----------------------

or

----------------------
Requests to log the memory contexts of the backend with the specified process ID. This function can send the request to also auxiliary processes except logger and stats collector.
----------------------

+ /* See if the process with given pid is an auxiliary process. */
+ if (proc == NULL)
+ {
+ proc = AuxiliaryPidGetProc(pid);
+ is_aux_proc = true;
+ }

As Horiguchi-san told upthread, IMO it's simpler not to use is_aux_proc flag. For example, you can replace this code with

------------------------
proc = BackendPidGetProc(pid);

if (proc != NULL)
backendId = proc->backendId;
else
proc = AuxiliaryPidGetProc(pid);
------------------------

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Finnerty, Jim 2022-01-07 15:53:51 Re: Add 64-bit XIDs into PostgreSQL 15
Previous Message Finnerty, Jim 2022-01-07 15:39:16 Re: Add 64-bit XIDs into PostgreSQL 15