Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kA3gB-00033D-ND for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Aug 2020 04:01:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kA3g9-0002F2-SO for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Aug 2020 04:01:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kA3g9-0002Eu-Ip for pgsql-hackers@lists.postgresql.org; Mon, 24 Aug 2020 04:01:53 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kA3g2-0003YW-Jd for pgsql-hackers@postgresql.org; Mon, 24 Aug 2020 04:01:52 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTP id DB23460560; Mon, 24 Aug 2020 13:01:42 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_c994a2a1fc55a1708b7f5ffea845b190" Date: Mon, 24 Aug 2020 13:01:42 +0900 From: torikoshia To: Michael Paquier , Kasahara Tatsuhito , Fujii Masao Cc: Andres Freund , Tom Lane , PostgreSQL-development , Robert Haas Subject: Re: Creating a function for exposing memory usage of backend process In-Reply-To: <20200822121641.GE2108@paquier.xyz> References: <261eebda3e1909475162b968e5a4ad2b@oss.nttdata.com> <66ae5b88-208d-96fa-c20a-fb539b597859@oss.nttdata.com> <20200819135545.GC19121@paquier.xyz> <1414992.1597849297@sss.pgh.pa.us> <20200819225343.c7rxteydi35nhrdp@alap3.anarazel.de> <1554676.1597886946@sss.pgh.pa.us> <20200820014301.5pr7qjugnvpovu62@alap3.anarazel.de> <20200822121641.GE2108@paquier.xyz> Message-ID: X-Sender: torikoshia@oss.nttdata.com User-Agent: Roundcube Webmail/1.1.9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_c994a2a1fc55a1708b7f5ffea845b190 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed 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/ or something >>> roughly >>> like that. >> >> Sounds good. Maybe we can also provide the SQL-callable function >> or view to read pg_memusage/, 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 --=_c994a2a1fc55a1708b7f5ffea845b190 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0001-Previously-pg_backend_memory_contexts-doesn-t-have-a.patch Content-Disposition: attachment; filename=0001-Previously-pg_backend_memory_contexts-doesn-t-have-a.patch; size=1704 RnJvbSBkYzRmYWRlOTExMWRjM2Y5MWU5OTJjNGQ1YWYzOTNkZDVlZDAzMjcwIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBBdHN1c2hpIFRvcmlrb3NoaSA8dG9yaWtvc2hpYUBvc3MubnR0 ZGF0YS5jb20+CkRhdGU6IE1vbiwgMjQgSnVsIDIwMjAgMTE6MTQ6MzIgKzA5MDAKU3ViamVjdDog W1BBVENIXSBQcmV2aW91c2x5IHBnX2JhY2tlbmRfbWVtb3J5X2NvbnRleHRzIGRvZXNuJ3QgaGF2 ZSBhbnkKIHJlc3RyaWN0aW9uIGFuZCBhbnlvbmUgY291bGQgYWNjZXNzIGl0LiBIb3dldmVyLCB0 aGlzIHZpZXcgY29udGFpbnMgc29tZQogaW50ZXJuYWwgaW5mb3JtYXRpb24gb2YgdGhlIG1lbW9y eSBjb250ZXh0LiBUaGlzIHBvbGljeSBjb3VsZCBjYXVzZSBzZWN1cml0eQogaXNzdWVzLiBUaGlz IHBhdGNoIHJldm9rZXMgYWxsIG9uIHBnX3NobWVtX2FsbG9jYXRpb25zIGZyb20gcHVibGljIGFu ZCBvbmx5CiB0aGUgc3VwZXJ1c2VycyBjY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