{"Entry":{"collection":"guc","key":"stats_fetch_consistency","name":"stats_fetch_consistency","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Statistics / Cumulative Query and Index Statistics","category_zh":"","changed_in":[],"changes":[{"documentation_changed":false,"fields":{},"from":"14","status":"added","to":"15"}],"content_hash":"6deecb5ab7487614534676bfcf079ca354204655d67bdcd7dbaee54c8ff84fbc","context":"","default_changed_in":[],"default_history":[{"from":"15","to":"19","value":"cache"}],"editorial":{"advice":{"olap":"Large catalogs make snapshot expensive; choose stats_fetch_consistency from the monitoring query's access pattern rather than workload label.","oltp":"Use cache for ordinary SQL, none for scrape queries that read each statistic once, and snapshot only for a deliberate coherent inspection. Do not hold a monitoring transaction open indefinitely.","small":"Keep cache unless a simple one-pass collector benefits from none. The setting changes read semantics, not collection accuracy."},"mechanism":["stats_fetch_consistency defines repeat-read behavior for cumulative statistics within one transaction. none refetches each object, cache retains each object after first access, and snapshot materializes all accessible database statistics on first access.","The cache or snapshot lasts until transaction end or pg_stat_clear_snapshot(). Changing the setting inside a transaction discards the current statistics snapshot.","none is efficient for monitoring queries that read each counter once; cache gives stable repeated object reads; snapshot gives a coherent interactive view at higher cost, especially with many objects. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value."],"pitfalls":["Enabling or enlarging stats_fetch_consistency without measuring collection and observation overhead.","Confusing collection semantics with a performance-control or I/O-control setting.","Assuming all statistics are immediately current inside a long transaction.","Collecting sensitive query text or identifiers without matching access and retention policy."],"references":[{"title":"PostgreSQL 19 Beta 4: stats_fetch_consistency","url":"https://www.postgresql.org/docs/19/runtime-config-statistics.html#GUC-STATS-FETCH-CONSISTENCY"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["track_counts","track_activities","track_io_timing","track_functions"],"summary":"stats_fetch_consistency — Sets the consistency of accesses to statistics data. Observed in PG15–19 Beta 4; its last measured boot default is cache in PG19 Beta 4, with user context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"15","group":"Statistics","group_slug":"statistics","imported_at":"2026-09-27T17:57:32.066794+08:00","intro_commit":{"authored_at":"2022-04-06T21:29:46-07:00","discussion":["https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de","https://postgr.es/m/20220308205351.2xcn6k4x5yivcxyd@alap3.anarazel.de","https://postgr.es/m/20210319235115.y3wz7hpnnrshdyv6@alap3.anarazel.de"],"hash":"5891c7a8ed8f2d3d577e7eea34dacff12d7b6bbd","subject":"pgstat: store statistics in shared memory.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=5891c7a8ed8f2d3d577e7eea34dacff12d7b6bbd"},"key":"stats_fetch_consistency","last_version":"20","max_val":"","min_val":"","name":"stats_fetch_consistency","position":388,"present_in":["15","16","17","18","19","20"],"short_desc":"Determines the behavior when cumulative statistics are accessed multiple times within a transaction.","short_desc_zh":"","source_rev":"english-manuals:e3f16b5be626d8553245746720e73a0c84674176630909018be34c8a7b985284","unit":"","vartype":"enum"}},"Definition":{"Collection":"guc","Key":"stats_fetch_consistency","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"stats_fetch_consistency","SourceRevision":"english-manuals:e3f16b5be626d8553245746720e73a0c84674176630909018be34c8a7b985284","Facts":{"boot_val":"cache","category":"Statistics / Cumulative Query and Index Statistics","context":"user","description":"Determines the behavior when cumulative statistics are accessed multiple times within a transaction. When set to none, each access re-fetches counters from shared memory. When set to cache, the first access to statistics for an object caches those statistics until the end of the transaction unless pg_stat_clear_snapshot() is called. When set to snapshot, the first statistics access caches all statistics accessible in the current database, until the end of the transaction unless pg_stat_clear_snapshot() is called. Changing this parameter in a transaction discards the statistics snapshot. The default is cache. Note none is most suitable for monitoring systems. If values are only accessed once, it is the most efficient. cache ensures repeat accesses yield the same values, which is important for queries involving e.g. self-joins. snapshot can be useful when interactively inspecting statistics, but has higher overhead, particularly if many database objects exist.","doc":{"anchor":"GUC-STATS-FETCH-CONSISTENCY","file":"runtime-config-statistics.html","lang":"en","sha256":"90db46d4b011d54f415934fcc658b0841d07af25ae591483c2139ba0e114ed21","slug":"18"},"documented":true,"enumvals":["none","cache","snapshot"],"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"stats_fetch_consistency","short_desc":"Sets the consistency of accesses to statistics data.","source":"pg-settings-source-snapshot","unit":null,"vartype":"enum"},"ManualEvidence":{"doc":{"anchor":"GUC-STATS-FETCH-CONSISTENCY","file":"runtime-config-statistics.html","lang":"en","sha256":"90db46d4b011d54f415934fcc658b0841d07af25ae591483c2139ba0e114ed21","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"stats_fetch_consistency","SourceDatabase":"center","Version":"18","Locale":"en","Title":"stats_fetch_consistency","Summary":"Determines the behavior when cumulative statistics are accessed multiple times within a transaction. When set to none, each access re-fetches counters from shared memory. When set to cache, the first access to statistics for an object caches those statistics until the end of the transaction unless pg_stat_clear_snapshot() is called. When set to snapshot, the first statistics access caches all statistics accessible in the current database, until the end of the transaction unless pg_stat_clear_snapshot() is called. Changing this parameter in a transaction discards the statistics snapshot. The default is cache. Note none is most suitable for monitoring systems. If values are only accessed once, it is the most efficient. cache ensures repeat accesses yield the same values, which is important for queries involving e.g. self-joins. snapshot can be useful when interactively inspecting statistics, but has higher overhead, particularly if many database objects exist.","BodyHTML":"\u003cp\u003eDetermines the behavior when cumulative statistics are accessed multiple times within a transaction. When set to none, each access re-fetches counters from shared memory. When set to cache, the first access to statistics for an object caches those statistics until the end of the transaction unless pg_stat_clear_snapshot() is called. When set to snapshot, the first statistics access caches all statistics accessible in the current database, until the end of the transaction unless pg_stat_clear_snapshot() is called. Changing this parameter in a transaction discards the statistics snapshot. The default is cache. Note none is most suitable for monitoring systems. If values are only accessed once, it is the most efficient. cache ensures repeat accesses yield the same values, which is important for queries involving e.g. self-joins. snapshot can be useful when interactively inspecting statistics, but has higher overhead, particularly if many database objects exist.\u003c/p\u003e","SourceRevision":"english-manuals:e3f16b5be626d8553245746720e73a0c84674176630909018be34c8a7b985284","ContentHash":"00b1c687d45720d677ab557717019b2823af30a714cf2619cd88be93614d2289","Payload":{"description":"Determines the behavior when cumulative statistics are accessed multiple times within a transaction. When set to none, each access re-fetches counters from shared memory. When set to cache, the first access to statistics for an object caches those statistics until the end of the transaction unless pg_stat_clear_snapshot() is called. When set to snapshot, the first statistics access caches all statistics accessible in the current database, until the end of the transaction unless pg_stat_clear_snapshot() is called. Changing this parameter in a transaction discards the statistics snapshot. The default is cache. Note none is most suitable for monitoring systems. If values are only accessed once, it is the most efficient. cache ensures repeat accesses yield the same values, which is important for queries involving e.g. self-joins. snapshot can be useful when interactively inspecting statistics, but has higher overhead, particularly if many database objects exist."}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
