Re: Creating a function for exposing memory usage of backend process
torikoshia <torikoshia@oss.nttdata.com>
From: torikoshia <torikoshia@oss.nttdata.com>
To: Michael Paquier <michael@paquier.xyz>, Kasahara Tatsuhito
<kasahara.tatsuhito@gmail.com>, Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: Andres Freund <andres@anarazel.de>, Tom Lane <tgl@sss.pgh.pa.us>,
PostgreSQL-development <pgsql-hackers@postgresql.org>, Robert Haas
<robertmhaas@gmail.com>
Date: 2020-08-24T04:01:42Z
Lists: pgsql-hackers
Attachments
- 0001-Previously-pg_backend_memory_contexts-doesn-t-have-a.patch (text/x-diff) patch 0001
On 2020-08-22 21:18, Michael Paquier wrote: Thanks for reviewing! > On Fri, Aug 21, 2020 at 11:27:06PM +0900, torikoshia wrote: >> OK. Added a regression test on sysviews.sql. >> (0001-Added-a-regression-test-for-pg_backend_memory_contex.patch) >> >> Fujii-san gave us an example, but I added more simple one considering >> the simplicity of other tests on that. > > What you have sent in 0001 looks fine to me. A small test is much > better than nothing. > >> Added a patch for relocating the codes to mcxtfuncs.c. >> (patches/0001-Rellocated-the-codes-for-pg_backend_memory_contexts-.patch) > > The same code is moved around line-by-line. > >> Of course, this restriction makes pg_backend_memory_contexts hard to >> use >> when the user of the target session is not granted pg_monitor because >> the >> scope of this view is session local. >> >> In this case, I imagine additional operations something like >> temporarily >> granting pg_monitor to that user. > > Hmm. I am not completely sure either that pg_monitor is the best fit > here, because this view provides information about a bunch of internal > structures. Something that could easily be done though is to revoke > the access from public, and then users could just set up GRANT > permissions post-initdb, with pg_monitor as one possible choice. This > is the safest path by default, and this stuff is of a caliber similar > to pg_shmem_allocations in terms of internal contents. I think this is a better way than what I did in 0001-Rellocated-the-codes-for-pg_backend_memory_contexts-.patch. Attached a patch. > > It seems to me that you are missing one "REVOKE ALL on > pg_backend_memory_contexts FROM PUBLIC" in patch 0003. > > By the way, if that was just for me, I would remove used_bytes, which > is just a computation from the total and free numbers. I'll defer > that point to Fujii-san. > -- > Michael On 2020/08/20 2:59, Kasahara Tatsuhito wrote: >>> I totally agree that it's not *enough*, but in contrast to you I >>> think >>> it's a good step. Subsequently we should add a way to get any >>> backends >>> memory usage. >>> It's not too hard to imagine how to serialize it in a way that can be >>> easily deserialized by another backend. I am imagining something like >>> sending a procsignal that triggers (probably at CFR() time) a backend >>> to >>> write its own memory usage into pg_memusage/<pid> or something >>> roughly >>> like that. >> >> Sounds good. Maybe we can also provide the SQL-callable function >> or view to read pg_memusage/<pid>, to make the analysis easier. > +1 I'm thinking about starting a new thread to discuss exposing other backend's memory context. Regards, -- Atsushi Torikoshi NTT DATA CORPORATION
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