Add assertion in pgstat_write_statsfile() about processes allowed
authorMichael Paquier <[email protected]>
Fri, 12 Jul 2024 06:09:53 +0000 (15:09 +0900)
committerMichael Paquier <[email protected]>
Fri, 12 Jul 2024 06:09:53 +0000 (15:09 +0900)
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/[email protected]

src/backend/utils/activity/pgstat.c

index f48b00b86bffc9b1f0b334c579440d4179fddff7..ed7baa6e04632a1c67f83f6fcf032dadcf75c47f 100644 (file)
@@ -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;