1212 * Statistics are loaded from the filesystem during startup (by the startup
1313 * process), unless preceded by a crash, in which case all stats are
1414 * discarded. They are written out by the checkpointer process just before
15- * shutting down, except when shutting down in immediate mode.
15+ * shutting down (if the stats kind allows it), except when shutting down in
16+ * immediate mode.
1617 *
1718 * Fixed-numbered stats are stored in plain (non-dynamic) shared memory.
1819 *
@@ -281,6 +282,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
281282 .name = "database" ,
282283
283284 .fixed_amount = false,
285+ .write_to_file = true,
284286 /* so pg_stat_database entries can be seen in all databases */
285287 .accessed_across_databases = true,
286288
@@ -297,6 +299,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
297299 .name = "relation" ,
298300
299301 .fixed_amount = false,
302+ .write_to_file = true,
300303
301304 .shared_size = sizeof (PgStatShared_Relation ),
302305 .shared_data_off = offsetof(PgStatShared_Relation , stats ),
@@ -311,6 +314,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
311314 .name = "function" ,
312315
313316 .fixed_amount = false,
317+ .write_to_file = true,
314318
315319 .shared_size = sizeof (PgStatShared_Function ),
316320 .shared_data_off = offsetof(PgStatShared_Function , stats ),
@@ -324,6 +328,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
324328 .name = "replslot" ,
325329
326330 .fixed_amount = false,
331+ .write_to_file = true,
327332
328333 .accessed_across_databases = true,
329334
@@ -340,6 +345,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
340345 .name = "subscription" ,
341346
342347 .fixed_amount = false,
348+ .write_to_file = true,
343349 /* so pg_stat_subscription_stats entries can be seen in all databases */
344350 .accessed_across_databases = true,
345351
@@ -359,6 +365,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
359365 .name = "archiver" ,
360366
361367 .fixed_amount = true,
368+ .write_to_file = true,
362369
363370 .snapshot_ctl_off = offsetof(PgStat_Snapshot , archiver ),
364371 .shared_ctl_off = offsetof(PgStat_ShmemControl , archiver ),
@@ -374,6 +381,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
374381 .name = "bgwriter" ,
375382
376383 .fixed_amount = true,
384+ .write_to_file = true,
377385
378386 .snapshot_ctl_off = offsetof(PgStat_Snapshot , bgwriter ),
379387 .shared_ctl_off = offsetof(PgStat_ShmemControl , bgwriter ),
@@ -389,6 +397,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
389397 .name = "checkpointer" ,
390398
391399 .fixed_amount = true,
400+ .write_to_file = true,
392401
393402 .snapshot_ctl_off = offsetof(PgStat_Snapshot , checkpointer ),
394403 .shared_ctl_off = offsetof(PgStat_ShmemControl , checkpointer ),
@@ -404,6 +413,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
404413 .name = "io" ,
405414
406415 .fixed_amount = true,
416+ .write_to_file = true,
407417
408418 .snapshot_ctl_off = offsetof(PgStat_Snapshot , io ),
409419 .shared_ctl_off = offsetof(PgStat_ShmemControl , io ),
@@ -421,6 +431,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
421431 .name = "slru" ,
422432
423433 .fixed_amount = true,
434+ .write_to_file = true,
424435
425436 .snapshot_ctl_off = offsetof(PgStat_Snapshot , slru ),
426437 .shared_ctl_off = offsetof(PgStat_ShmemControl , slru ),
@@ -438,6 +449,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
438449 .name = "wal" ,
439450
440451 .fixed_amount = true,
452+ .write_to_file = true,
441453
442454 .snapshot_ctl_off = offsetof(PgStat_Snapshot , wal ),
443455 .shared_ctl_off = offsetof(PgStat_ShmemControl , wal ),
@@ -1617,6 +1629,10 @@ pgstat_write_statsfile(XLogRecPtr redo)
16171629 if (pgstat_is_kind_builtin (kind ))
16181630 Assert (info -> snapshot_ctl_off != 0 );
16191631
1632+ /* skip if no need to write to file */
1633+ if (!info -> write_to_file )
1634+ continue ;
1635+
16201636 pgstat_build_snapshot_fixed (kind );
16211637 if (pgstat_is_kind_builtin (kind ))
16221638 ptr = ((char * ) & pgStatLocal .snapshot ) + info -> snapshot_ctl_off ;
@@ -1663,6 +1679,10 @@ pgstat_write_statsfile(XLogRecPtr redo)
16631679 /* if not dropped the valid-entry refcount should exist */
16641680 Assert (pg_atomic_read_u32 (& ps -> refcount ) > 0 );
16651681
1682+ /* skip if no need to write to file */
1683+ if (!kind_info -> write_to_file )
1684+ continue ;
1685+
16661686 if (!kind_info -> to_serialized_name )
16671687 {
16681688 /* normal stats entry, identified by PgStat_HashKey */
0 commit comments