summaryrefslogtreecommitdiff
path: root/src/backend/postmaster/pgstat.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-05-13 22:48:09 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-05-13 22:48:26 -0400
commit7fd89f4d7a51af77175a876613cffb490b9e5df1 (patch)
tree48c2a1d47b328e04d04a8c98200225cf4999c864 /src/backend/postmaster/pgstat.c
parentd82a5058fdb5905abc9867da302000c39aa30f01 (diff)
Fix async.c to not register any SLRU stats counts in the postmaster.
Previously, AsyncShmemInit forcibly initialized the first page of the async SLRU, to save dealing with that case in asyncQueueAddEntries. But this is a poor tradeoff, since many installations do not ever use NOTIFY; for them, expending those cycles in AsyncShmemInit is a complete waste. Besides, this only saves a couple of instructions in asyncQueueAddEntries, which hardly seems likely to be measurable. The real reason to change this now, though, is that now that we track SLRU access stats, the existing code is causing the postmaster to accumulate some access counts, which then get inherited into child processes by fork(), messing up the statistics. Delaying the initialization into the first child that does a NOTIFY fixes that. Hence, we can revert f3d23d83e, which was an incorrect attempt at fixing that issue. Also, add an Assert to pgstat.c that should catch any future errors of the same sort. Discussion: https://postgr.es/m/8367.1589391884@sss.pgh.pa.us
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r--src/backend/postmaster/pgstat.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 80a06e58ef2..0ecd29a1d99 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -2906,9 +2906,6 @@ pgstat_initialize(void)
MyBEEntry = &BackendStatusArray[MaxBackends + MyAuxProcType];
}
- /* Initialize SLRU statistics to zero */
- memset(&SLRUStats, 0, sizeof(SLRUStats));
-
/* Set up a process-exit hook to clean up */
on_shmem_exit(pgstat_beshutdown_hook, 0);
}
@@ -6727,6 +6724,12 @@ pgstat_slru_name(int slru_idx)
static inline PgStat_MsgSLRU *
slru_entry(int slru_idx)
{
+ /*
+ * The postmaster should never register any SLRU statistics counts; if it
+ * did, the counts would be duplicated into child processes via fork().
+ */
+ Assert(IsUnderPostmaster || !IsPostmasterEnvironment);
+
Assert((slru_idx >= 0) && (slru_idx < SLRU_NUM_ELEMENTS));
return &SLRUStats[slru_idx];