Hi,
With commit 32d3ed81, pg_backend_memory_contexts view will start
numbering memory context levels from 1 instead of 0 in PostgreSQL 18.
For example:
=# select name, level from pg_backend_memory_contexts;
name | level
----------------------------+-------
TopMemoryContext | 1
Record information cache | 2
Btree proof lookup cache | 2
However, pg_log_backend_memory_contexts() still starts its output from
level 0:
=# select pg_log_backend_memory_contexts(pg_backend_pid());
LOG: level: 0; TopMemoryContext: ...
LOG: level: 1; Record information cache: ...
LOG: level: 1; Btree proof lookup cache: ...
I understand that these view and function are intended primarily for
one-off diagnostics and not for direct cross-comparison. So this
discrepancy isn’t critical.
However, for the sake of consistency and to avoid potential confusion,
would it make sense to also start the levels from 1 in
pg_log_backend_memory_contexts() starting in v18?
--
Regards,
--
Atsushi Torikoshi
Seconded from NTT DATA GROUP CORPORATION to SRA OSS K.K.
From 7238f29804dc4f027a6e148f5f755d369c4d349c Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <toriko...@sraoss.co.jp>
Date: Tue, 15 Apr 2025 21:55:39 +0900
Subject: [PATCH v1] Increment level in pg_log_backend_memory_contexts()
Since commit 32d3ed81, pg_backend_memory_contexts reports memory context
levels starting from 1 instead of 0. For consistency, this patch makes
pg_log_backend_memory_contexts() do the same.
These outputs are primarily used for diagnostics and are not meant to be
compared directly, but aligning them may reduce confusion.
---
src/backend/utils/mmgr/mcxt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 1f5ebf2e12..54ee8af41f 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -1113,7 +1113,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
(errhidestmt(true),
errhidecontext(true),
errmsg_internal("level: %d; %s: %s%s",
- level, name, stats_string, truncated_ident)));
+ level + 1, name, stats_string, truncated_ident)));
}
/*
base-commit: c55df7c6eae5a5c6f91cd029fb91913db7f2089c
--
2.43.0