stats_fetch_consistency
Fact — official short description: “Sets the consistency of accesses to statistics data.”
Identity
Lifecycle
| Fact | Value |
|---|---|
| First observed | PG15 |
| Present in | PG15–19 Beta 3 |
| Removed in | No |
| Introduction commit | 5891c7a8ed8f — pgstat: store statistics in shared memory. |
| Commit date | 2022-04-06 |
| Discussion | thread 1 · thread 2 · thread 3 |
Default history
| Versions | Raw boot_val |
Unit | Human value |
|---|---|---|---|
| PG15–19 Beta 3 | cache |
— | cache |
How it works
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.
Tuning advice
Advice. These are workload-specific starting points and must be validated with measurements.
| Workload | Guidance |
|---|---|
| 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. |
| OLAP | Large catalogs make snapshot expensive; choose stats_fetch_consistency from the monitoring query’s access pattern rather than workload label. |
| Small nodes | Keep cache unless a simple one-pass collector benefits from none. The setting changes read semantics, not collection accuracy. |
Pigsty
Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.
| Template | Effective value | Versus upstream boot | Source expression |
|---|---|---|---|
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
Advice — pending human review. Fact from the current Pigsty template projection: OLTP: PG15–19 Beta 3 unmodified; OLAP: PG15–19 Beta 3 unmodified; CRIT: PG15–19 Beta 3 unmodified; TINY: PG15–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.
Common 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.
Related parameters
track_counts · track_activities · track_io_timing · track_functions
References
- PostgreSQL 19 Beta 3 — stats_fetch_consistency
- PostgreSQL 19 release notes
- Machine-readable GUC export