{"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"}],"derived_content_hash":"4990609a30e49e02067f3d0d0c0706a37a9188522ba3e52e8d770a75dbe935c8","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"],"repair_provenance":{"original_source_revision":"english-manuals:e3f16b5be626d8553245746720e73a0c84674176630909018be34c8a7b985284","receipt_sha256":"f790250a0854bfe9f237cba953cbfe7a57829841ffbc00612d84434a4a48ebf7","repair":"wiki-repair-20261023"},"short_desc":"Determines the behavior when cumulative statistics are accessed multiple times within a transaction.","short_desc_zh":"","source_rev":"wiki-repair-20261023:6ec790656e474029978a6f2d577cc5a0f5936eb4e46508f41a3e8e1c156c5e6c","unit":"","vartype":"enum"}},"Definition":{"Collection":"guc","Key":"stats_fetch_consistency","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"stats_fetch_consistency","SourceRevision":"wiki-repair-20261023:6ec790656e474029978a6f2d577cc5a0f5936eb4e46508f41a3e8e1c156c5e6c","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.","description_zh":"确定在事务中多次访问累积统计信息时的行为。当设置为 none 时，每次访问都会重新从共享内存中获取计数器。当设置为 cache 时，对对象的统计信息的第一次访问会将这些统计信息缓存，直到事务结束，除非调用 pg_stat_clear_snapshot()。当设置为 snapshot 时，第一次访问统计信息会缓存当前数据库中所有可访问的统计信息，直到事务结束，除非调用 pg_stat_clear_snapshot()。在事务中更改此参数会丢弃统计快照。默认值为 cache。 注意 none 最适合监控系统。如果值只被访问一次，它是最有效的。cache 确保重复访问产生相同的值，这对涉及自连接的查询很重要。snapshot 在交互式检查统计信息时可能很有用，但开销较高，特别是存在许多数据库对象时。","description_zh_html":"\u003cp\u003e\n        确定在事务中多次访问累积统计信息时的行为。当设置为\n        \u003ccode class=\"literal\"\u003enone\u003c/code\u003e 时，每次访问都会重新从共享内存中获取计数器。当设置为 \u003ccode class=\"literal\"\u003ecache\u003c/code\u003e 时，对对象的统计信息的第一次访问会将这些统计信息缓存，直到事务结束，除非调用 \u003ccode class=\"function\"\u003epg_stat_clear_snapshot()\u003c/code\u003e。当设置为 \u003ccode class=\"literal\"\u003esnapshot\u003c/code\u003e 时，第一次访问统计信息会缓存当前数据库中所有可访问的统计信息，直到事务结束，除非调用 \u003ccode class=\"function\"\u003epg_stat_clear_snapshot()\u003c/code\u003e。在事务中更改此参数会丢弃统计快照。默认值为 \u003ccode class=\"literal\"\u003ecache\u003c/code\u003e。\n       \u003c/p\u003e\u003cdiv class=\"note\"\u003e\u003ch3 class=\"title\"\u003e注意\u003c/h3\u003e\u003cp\u003e\n\u003ccode class=\"literal\"\u003enone\u003c/code\u003e 最适合监控系统。如果值只被访问一次，它是最有效的。\u003ccode class=\"literal\"\u003ecache\u003c/code\u003e 确保重复访问产生相同的值，这对涉及自连接的查询很重要。\u003ccode class=\"literal\"\u003esnapshot\u003c/code\u003e 在交互式检查统计信息时可能很有用，但开销较高，特别是存在许多数据库对象时。\n        \u003c/p\u003e\u003c/div\u003e","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","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-statistics.html","sha256":"e652c12bbb8be47104e61d6cde2c9e6d55a0abab5eb2f7eedf64ef2467356274"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":null,"vartype":"enum","zh_from":"same-version-pgdoc"},"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":"wiki-repair-20261023:6ec790656e474029978a6f2d577cc5a0f5936eb4e46508f41a3e8e1c156c5e6c","ContentHash":"57e21a28e0fb67d7d14ef718f3a69950ad3d990f874bb1561e4db805a4c8bde1","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":"en","Fallback":false,"Versions":["15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
