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
This commit is contained in:
Michael Paquier 2024-07-12 15:09:53 +09:00
parent 63909da978
commit 734c057a89
1 changed files with 3 additions and 0 deletions

View 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;