Parameter · Statistics / Cumulative Query and Index Statistics
track_counts
Collects statistics on database activity.
- Default:
on - Type: bool
- Applies: Session (superuser)
In plain words
PostgreSQL counts what happens to every table and index: rows inserted, updated, deleted, how many are dead, how often each is scanned. Autovacuum uses these counters to decide which tables need vacuuming or analyzing.
If you turn this off, the counters freeze and autovacuum can no longer see that tables need work: bloat and stale statistics follow.
For DBAs and operators
These counters feed pg_stat_user_tables (seq_scan, idx_scan, n_tup_ins/upd/del/hot_upd, n_live_tup, n_dead_tup, n_mod_since_analyze, n_ins_since_vacuum), pg_stat_user_indexes, pg_statio_* and the transaction/tuple columns of pg_stat_database.
Verified on 18.6: a session with SET track_counts = off inserted 100 rows, another session with it on inserted 10: n_tup_ins = 10, n_live_tup = 10. Changes made while it is off are never counted, so autovacuum's thresholds (based on n_dead_tup and n_mod_since_analyze) are never reached for that work.
Each backend collects its counters locally and flushes them to shared memory just before going idle, but not more than once a second, so they lag slightly. They are written to pg_stat/pgstat.stat at clean shutdown and reset after a crash or immediate shutdown; right after crash recovery autovacuum has no history to work with, so consider a manual VACUUM ANALYZE of busy tables.
Support tip: autovacuum "never runs" on a table? Check SHOW track_counts and per-database/role overrides in pg_db_role_setting before tuning thresholds.
How to change it
A superuser (or a role granted SET) can change it per session with SET.
See it in context
Cumulative statistics Autovacuum: when tables get vacuumed VACUUM Autovacuum launcher and workers
Related parameters
autovacuum track_activities track_io_timing autovacuum_vacuum_threshold