On Fri, 2022-07-29 at 11:53 +0900, Kyotaro Horiguchi wrote: > > That makes the memorycontext-tree structure unstable because > CacheMemoryContext can be created on-the-fly. > > Honestly I don't like to call CreateCacheMemoryContext in the two > functions on-the-fly. Since every process that calls > pgstat_initialize() necessarily calls pgstat_setup_memcxt() at latest > at process termination, I think we can create at least > CacheMemoryContext in pgstat_initialize().
Attached is a patch creating CacheMemoryContext() in pgstat_initialize() rather than the two previous patch locations. > Or couldn't we create the > all three contexts in the function, instead of calling > pgstat_setup_memcxt() on-the fly? You note that that pgstat_setup_memcxt() is called at latest at process termination -- was the intent to hold off on requesting memory for these two contexts until it was needed? > regards. > > -- > Kyotaro Horiguchi > NTT Open Source Software Center -- Reid Thompson Senior Software Engineer Crunchy Data, Inc. reid.thomp...@crunchydata.com www.crunchydata.com
diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index ffd096405e..b5b69ead2b 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -532,6 +532,8 @@ pgstat_initialize(void) /* Set up a process-exit hook to clean up */ before_shmem_exit(pgstat_shutdown_hook, 0); + CreateCacheMemoryContext(); + #ifdef USE_ASSERT_CHECKING pgstat_is_initialized = true; #endif