Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix stats_fetch_consistency with stats for fixed-numbered objects
authorMichael Paquier <michael@paquier.xyz>
Thu, 1 Feb 2024 08:13:11 +0000 (17:13 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 1 Feb 2024 08:13:11 +0000 (17:13 +0900)
This impacts the statistics retrieved in transactions for the following
views when updating the value of stats_fetch_consistency, leading to
behaviors contrary to what is documented since 605994651b6a as an update
of this parameter should discard all statistics snapshot data:
- pg_stat_archiver
- pg_stat_bgwriter
- pg_stat_checkpointer
- pg_stat_io
- pg_stat_slru
- pg_stat_wal

For example, updating stats_fetch_consistency from "snapshot" to "cache"
in a transaction did not re-fetch any fresh data, using data cached from
the time when "snapshot" was in use.

Author: Shinya Kato
Discussion: https://postgr.es/m/d77fc5190d4dbe1738d77231488e768b@oss.nttdata.com
Backpatch-through: 15

src/backend/utils/activity/pgstat.c

index 84d65a76af17deb9fe3a036d4f8051a89be21079..142e26af52e51618ea81fba25c3a6e8bb13548f6 100644 (file)
@@ -918,6 +918,9 @@ pgstat_snapshot_fixed(PgStat_Kind kind)
    AssertArg(pgstat_is_kind_valid(kind));
    AssertArg(pgstat_get_kind_info(kind)->fixed_amount);
 
+   if (force_stats_snapshot_clear)
+       pgstat_clear_snapshot();
+
    if (pgstat_fetch_consistency == PGSTAT_FETCH_CONSISTENCY_SNAPSHOT)
        pgstat_build_snapshot();
    else