Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSQ1W-00ECzq-1J for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 01:26:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSQ1U-00EMgP-36 for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 01:26:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSQ1U-00EMgH-2B for pgsql-hackers@lists.postgresql.org; Mon, 08 Dec 2025 01:26:44 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSQ1R-003lEi-2g for pgsql-hackers@postgresql.org; Mon, 08 Dec 2025 01:26:44 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 6B8E961B8E; Mon, 8 Dec 2025 10:26:34 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Mon, 08 Dec 2025 10:26:33 +0900 From: torikoshia To: Rahila Syed Cc: Daniel Gustafsson , PostgreSQL Hackers Subject: Re: Enhancing Memory Context Statistics Reporting In-Reply-To: References: <54FAE93D-E156-4684-9352-1CEDE6BD4A1C@yesql.se> <5bxhxniyvjyfldi7yjxcnxkl3i2ghci2grjyeclrbkfqnyhowk@dfkqzbvtbpml> <3eb40b3e-45c7-426a-b7f8-81f7d05a9b53@oss.nttdata.com> <74105887-E4EF-4CA2-9F0A-3C0CE05BF632@yesql.se> <437100f2-dd86-42e6-830c-5ff413a25e8e@oss.nttdata.com> <2a796830-de2d-4030-b480-d673f6cc5d94@eisentraut.org> <02E42650-0C66-4B49-93CA-1B0A5B73E7FD@yesql.se> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <44a9d3857aaed49b818dc893dde9f6b4@oss.nttdata.com> X-Sender: torikoshia@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-11-28 18:22, Rahila Syed wrote: Hi, > I'm attaching the updated patches, which primarily include cleanup and > have been rebased > following the CFbot report. Thanks for updating the patch! I observed an assertion failure when forcing a timeout as follows: ``` $ psql (pid:38587)=# $ kill -s SIGSTOP 38587 $ psql (pid:38618) =# select * from pg_get_process_memory_contexts(38587, false); name | ident | type | level | path | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes | num_agg_contexts --------+--------+--------+--------+--------+-------------+---------------+------------+-------------+------------+------------------ [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] | [NULL] (1 row) Time: 5013.515 ms (00:05.014) $ kill -s SIGCONT 38587 $ tail postgresql.log TRAP: failed Assert("client_keys[MyProcNumber] != -1"), File: "mcxtfuncs.c", Line: 881, PID: 38587 0 postgres 0x0000000104943400 ExceptionalCondition + 216 1 postgres 0x000000010480f738 ProcessGetMemoryContextInterrupt + 140 2 postgres 0x00000001046f2710 ProcessInterrupts + 3008 3 postgres 0x00000001046f1a78 ProcessClientReadInterrupt + 80 4 postgres 0x0000000104433994 secure_read + 404 5 postgres 0x00000001044411dc pq_recvbuf + 260 6 postgres 0x0000000104441088 pq_getbyte + 96 7 postgres 0x00000001046fa0fc SocketBackend + 44 8 postgres 0x00000001046f6d3c ReadCommand + 44 9 postgres 0x00000001046f6284 PostgresMain + 2900 10 postgres 0x00000001046ed558 BackendInitialize + 0 11 postgres 0x00000001045c0a48 postmaster_child_launch + 456 12 postgres 0x00000001045c8520 BackendStartup + 304 13 postgres 0x00000001045c636c ServerLoop + 372 14 postgres 0x00000001045c4e24 PostmasterMain + 6448 15 postgres 0x0000000104445b4c main + 924 16 dyld 0x0000000188662b98 start + 6076 2025-12-08 07:35:32.608 JST [38540] LOG: 00000: client backend (PID 38587) was terminated by signal 6: Abort trap: 6 2025-12-08 07:35:32.608 JST [38540] LOCATION: LogChildExit, postmaster.c:2872 ``` Below are comments regarding the v42-0001 patch: > In order to not block on busy processes, we have hardcoded > the number of seconds during which to retry before timing out. > In the case where no statistics are published within the set > timeout, NULL is returned. It might be good to also document in func-admin.sgml that the function times out after 5 seconds when the target backend does not respond, and that in such a case NULLs are returned. + * If DSA exists, created by another process requesting statistics, attach + * to it. We expect the client process to create required DSA and Dshash + * table. + */ + if (MemoryStatsDsaArea == NULL) + MemoryStatsDsaArea = GetNamedDSA("memory_context_statistics_dsa", + &found); + + if (MemoryStatsDsHash == NULL) + MemoryStatsDsHash = GetNamedDSHash("memory_context_statistics_dshash", + &memctx_dsh_params, &found); From the comment, it sounded to me as if the client executing pg_get_process_memory_contexts() might not create the DSA in some cases. Is it correct to assume that such a situation can happen? In [1], as a response to concerns about using DSA inside a CFI handler, you wrote that “all the dynamic shared memory needed to store the statistics is created and deleted in the client function”. So I understood that it would never create the DSA inside the CFI handler. If that understanding is correct, perhaps the comment should be reworded to make that clear. + context_id_lookup = hash_create("pg_get_remote_backend_memory_contexts", This appears to use the old function name. Should this be updated to "pg_get_process_memory_contexts" instead? [1] https://www.postgresql.org/message-id/CAH2L28sc-rEhyntPLoaC2XUa0ZjS5ka6KzEbuSVxQBBnUYu1KQ%40mail.gmail.com -- Regards, -- Atsushi Torikoshi Seconded from NTT DATA Japan Corporation to SRA OSS K.K.