12
12
* Statistics are loaded from the filesystem during startup (by the startup
13
13
* process), unless preceded by a crash, in which case all stats are
14
14
* 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.
16
17
*
17
18
* Fixed-numbered stats are stored in plain (non-dynamic) shared memory.
18
19
*
@@ -281,6 +282,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
281
282
.name = "database" ,
282
283
283
284
.fixed_amount = false,
285
+ .write_to_file = true,
284
286
/* so pg_stat_database entries can be seen in all databases */
285
287
.accessed_across_databases = true,
286
288
@@ -297,6 +299,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
297
299
.name = "relation" ,
298
300
299
301
.fixed_amount = false,
302
+ .write_to_file = true,
300
303
301
304
.shared_size = sizeof (PgStatShared_Relation ),
302
305
.shared_data_off = offsetof(PgStatShared_Relation , stats ),
@@ -311,6 +314,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
311
314
.name = "function" ,
312
315
313
316
.fixed_amount = false,
317
+ .write_to_file = true,
314
318
315
319
.shared_size = sizeof (PgStatShared_Function ),
316
320
.shared_data_off = offsetof(PgStatShared_Function , stats ),
@@ -324,6 +328,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
324
328
.name = "replslot" ,
325
329
326
330
.fixed_amount = false,
331
+ .write_to_file = true,
327
332
328
333
.accessed_across_databases = true,
329
334
@@ -340,6 +345,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
340
345
.name = "subscription" ,
341
346
342
347
.fixed_amount = false,
348
+ .write_to_file = true,
343
349
/* so pg_stat_subscription_stats entries can be seen in all databases */
344
350
.accessed_across_databases = true,
345
351
@@ -359,6 +365,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
359
365
.name = "archiver" ,
360
366
361
367
.fixed_amount = true,
368
+ .write_to_file = true,
362
369
363
370
.snapshot_ctl_off = offsetof(PgStat_Snapshot , archiver ),
364
371
.shared_ctl_off = offsetof(PgStat_ShmemControl , archiver ),
@@ -374,6 +381,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
374
381
.name = "bgwriter" ,
375
382
376
383
.fixed_amount = true,
384
+ .write_to_file = true,
377
385
378
386
.snapshot_ctl_off = offsetof(PgStat_Snapshot , bgwriter ),
379
387
.shared_ctl_off = offsetof(PgStat_ShmemControl , bgwriter ),
@@ -389,6 +397,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
389
397
.name = "checkpointer" ,
390
398
391
399
.fixed_amount = true,
400
+ .write_to_file = true,
392
401
393
402
.snapshot_ctl_off = offsetof(PgStat_Snapshot , checkpointer ),
394
403
.shared_ctl_off = offsetof(PgStat_ShmemControl , checkpointer ),
@@ -404,6 +413,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
404
413
.name = "io" ,
405
414
406
415
.fixed_amount = true,
416
+ .write_to_file = true,
407
417
408
418
.snapshot_ctl_off = offsetof(PgStat_Snapshot , io ),
409
419
.shared_ctl_off = offsetof(PgStat_ShmemControl , io ),
@@ -421,6 +431,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
421
431
.name = "slru" ,
422
432
423
433
.fixed_amount = true,
434
+ .write_to_file = true,
424
435
425
436
.snapshot_ctl_off = offsetof(PgStat_Snapshot , slru ),
426
437
.shared_ctl_off = offsetof(PgStat_ShmemControl , slru ),
@@ -438,6 +449,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
438
449
.name = "wal" ,
439
450
440
451
.fixed_amount = true,
452
+ .write_to_file = true,
441
453
442
454
.snapshot_ctl_off = offsetof(PgStat_Snapshot , wal ),
443
455
.shared_ctl_off = offsetof(PgStat_ShmemControl , wal ),
@@ -1617,6 +1629,10 @@ pgstat_write_statsfile(XLogRecPtr redo)
1617
1629
if (pgstat_is_kind_builtin (kind ))
1618
1630
Assert (info -> snapshot_ctl_off != 0 );
1619
1631
1632
+ /* skip if no need to write to file */
1633
+ if (!info -> write_to_file )
1634
+ continue ;
1635
+
1620
1636
pgstat_build_snapshot_fixed (kind );
1621
1637
if (pgstat_is_kind_builtin (kind ))
1622
1638
ptr = ((char * ) & pgStatLocal .snapshot ) + info -> snapshot_ctl_off ;
@@ -1663,6 +1679,10 @@ pgstat_write_statsfile(XLogRecPtr redo)
1663
1679
/* if not dropped the valid-entry refcount should exist */
1664
1680
Assert (pg_atomic_read_u32 (& ps -> refcount ) > 0 );
1665
1681
1682
+ /* skip if no need to write to file */
1683
+ if (!kind_info -> write_to_file )
1684
+ continue ;
1685
+
1666
1686
if (!kind_info -> to_serialized_name )
1667
1687
{
1668
1688
/* normal stats entry, identified by PgStat_HashKey */
0 commit comments