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 1kAC1K-00054k-L8 for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Aug 2020 12:56:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kAC1H-00037V-V2 for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Aug 2020 12:56:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kAC1H-00037I-NX for pgsql-hackers@lists.postgresql.org; Mon, 24 Aug 2020 12:56:15 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kAC1D-0006EQ-72 for pgsql-hackers@postgresql.org; Mon, 24 Aug 2020 12:56:14 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTP id 7B2A462311; Mon, 24 Aug 2020 21:56:06 +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="=_4a266b3c4573ff31d36757f2c63082d7" Date: Mon, 24 Aug 2020 21:56:06 +0900 From: torikoshia To: Fujii Masao Cc: Michael Paquier , Kasahara Tatsuhito , Andres Freund , Tom Lane , PostgreSQL-development , Robert Haas Subject: Re: Creating a function for exposing memory usage of backend process In-Reply-To: <07da4267-74bf-4a6b-3312-4ab7c1e72f66@oss.nttdata.com> 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> <07da4267-74bf-4a6b-3312-4ab7c1e72f66@oss.nttdata.com> 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 --=_4a266b3c4573ff31d36757f2c63082d7 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed On 2020-08-24 13:13, Fujii Masao wrote: > On 2020/08/24 13:01, torikoshia wrote: >> 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. > > +1 > > But as I proposed upthread, what about a bit complicated test as > follows, > e.g., to confirm that the internal logic for level works expectedly? > > SELECT name, ident, parent, level, total_bytes >= free_bytes FROM > pg_backend_memory_contexts WHERE level = 0; OK! Attached an updated patch. > > >>> >>>> Added a patch for relocating the codes to mcxtfuncs.c. >>>> (patches/0001-Rellocated-the-codes-for-pg_backend_memory_contexts-.patch) > > Thanks for the patch! Looks good to me. > Barring any objection, I will commit this patch at first. > > >>> >>> 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. > > You mean > 0001-Restrict-the-access-to-pg_backend_memory_contexts-to.patch? Oops, I meant 0001-Restrict-the-access-to-pg_backend_memory_contexts-to.patch. > > >> Attached a patch. > > Thanks for updating the patch! This also looks good to me. > > >>> 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. > > Yeah, I was just thinking that displaying also used_bytes was useful, > but this might be inconsistent with the other views' ways. > > Regards, Regards, -- Atsushi Torikoshi NTT DATA CORPORATION --=_4a266b3c4573ff31d36757f2c63082d7 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0002-Added-a-regression-test-for-pg_backend_memory_contex.patch Content-Disposition: attachment; filename=0002-Added-a-regression-test-for-pg_backend_memory_contex.patch; size=1940 RnJvbSAzMzViOWViMGM2MGE3ZjEyZGViZDRjNDVkNDM1ODg4MTA5YjJiZmNmIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBBdHN1c2hpIFRvcmlrb3NoaSA8dG9yaWtvc2hpYUBvc3MubnR0 ZGF0YS5jb20+CkRhdGU6IE1vbiwgMjQgQXVnIDIwMjAgMjE6Mjg6MjAgKzA5MDAKU3ViamVjdDog W1BBVENIXSBBZGRlZCBhIHJlZ3Jlc3Npb24gdGVzdCBmb3IgcGdfYmFja2VuZF9tZW1vcnlfY29u dGV4dHMuCgotLS0KIHNyYy90ZXN0L3JlZ3Jlc3MvZXhwZWN0ZWQvc3lzdmlld3Mub3V0IHwgOSAr KysrKysrKysKIHNyYy90ZXN0L3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