From 734c057a8935fca10ff67173c8b969ef799ea7d2 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 12 Jul 2024 15:09:53 +0900 Subject: [PATCH] Add assertion in pgstat_write_statsfile() about processes allowed This routine can currently only be called from the postmaster in single-user mode or the checkpointer, but there was no sanity check to make sure that this was always the case. This has proved to be useful when hacking the zone (at least to me), to make sure that the write of the pgstats file happens at shutdown, as wanted by design, in the correct process context. Discussion: https://postgr.es/m/ZnEiqAITL-VgZDoY@paquier.xyz --- src/backend/utils/activity/pgstat.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index f48b00b86bf..ed7baa6e046 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -1360,6 +1360,9 @@ pgstat_write_statsfile(void) pgstat_assert_is_up(); + /* should be called only by the checkpointer or single user mode */ + Assert(!IsUnderPostmaster || MyBackendType == B_CHECKPOINTER); + /* we're shutting down, so it's ok to just override this */ pgstat_fetch_consistency = PGSTAT_FETCH_CONSISTENCY_NONE;