skip to content

In PostgreSQL 18, what does eager freezing change for an append-mostly telemetry table, and what does vacuum_max_eager_freeze_failure_rate control?

level: middleimportance: nice to knowfreq 24%

answer

  1. all-visible is not all-frozen
  2. the one big aggressive vacuum
  3. normal vacuums freeze a little
  4. a 20% success cap, a 3% failure cap

basics

~10 s

Before 18, normal vacuums skipped all-visible pages, leaving freezing to one huge aggressive vacuum. PostgreSQL 18 lets normal vacuums eagerly freeze some all-visible pages; vacuum_max_eager_freeze_failure_rate (default 0.03) caps failed attempts before eager scanning pauses.

solid answer

~40 s

An append-mostly table such as IoT readings gets vacuumed by insert-triggered autovacuum, its pages become **all-visible**, and normal vacuums then skip them. Before PostgreSQL 18 nothing froze those pages until the table's age passed `vacuum_freeze_table_age` (150 million) or `autovacuum_freeze_max_age` (200 million), and one aggressive vacuum had to read and freeze the whole backlog at once. In 18 a normal vacuum may **eagerly scan** some all-visible but not all-frozen pages and freeze them. Successes are capped internally at 20% of that backlog per vacuum; `vacuum_max_eager_freeze_failure_rate` (default `0.03`, also a per-table storage parameter) caps how many scanned pages may fail to become all-frozen before eager scanning pauses, and `0` disables it. Aggressive vacuums still happen but skip already-frozen pages. VERBOSE reports `eagerly scanned` pages, and the new `pg_class.relallfrozen` shows progress.

code

sql · 14 lines
sql
-- Append-only readings: tolerate more failed eager attempts per region
ALTER TABLE telemetry.readings
  SET (vacuum_max_eager_freeze_failure_rate = 0.10);

-- Frequently updated device registry: no eager scanning
ALTER TABLE telemetry.devices
  SET (vacuum_max_eager_freeze_failure_rate = 0);

-- Backlog the next aggressive vacuum would face (PostgreSQL 18)
SELECT relname, relpages, relallvisible, relallfrozen,
       relallvisible - relallfrozen AS visible_not_frozen,
       age(relfrozenxid)            AS xid_age
FROM pg_class
WHERE oid IN ('telemetry.readings'::regclass, 'telemetry.devices'::regclass);

go deeper

for a junior

Know that PostgreSQL 18 lets ordinary vacuums freeze some pages early, so append-only tables avoid one huge freezing pass later.

for a middle

Explain all-visible versus all-frozen, why pre-18 normal vacuums left a freeze backlog, and what the 20% success cap and the 0.03 failure rate each limit.

for a senior

Tune per table: higher rates for append-only data, 0 for hot rows, read relallvisible against relallfrozen, and remember aggressive vacuums still run and still advance relfrozenxid.

for a principal

Judge whether spreading freezing I/O across routine vacuums beats scheduling one controlled freeze pass, given WAL volume, replicas and the I/O budget of the ingest path.

## The freeze backlog on append-mostly tables An IoT `telemetry.readings` table is **append-mostly**: rows are inserted and read, but almost never updated. Insert-triggered autovacuum (the autovacuum leaf's subject) visits such a table and marks its pages **all-visible** in the visibility map, which lets later normal vacuums **skip** them. That skipping is good for dead-row cleanup but leaves freezing undone. Before PostgreSQL 18, a normal vacuum never processed all-visible pages until freezing was required, so unfrozen pages piled up as **all-visible but not all-frozen**. Then, once the table's `relfrozenxid` age passed `vacuum_freeze_table_age` (150 million) or `autovacuum_freeze_max_age` (200 million), one **aggressive vacuum** had to read and freeze the entire backlog in one go: heavy reads, a burst of WAL and dirty pages, often on the largest table in the database, at a moment chosen by the XID counter rather than by you. ## What 18 changes: eager scanning PostgreSQL 18 lets a **normal** vacuum also scan some skippable all-visible pages in an attempt to freeze them; these are **eagerly scanned** pages. Pages frozen successfully are marked all-frozen and are skipped by the next aggressive vacuum, so the cost of freezing is spread over many ordinary vacuums instead of arriving as one spike. Eager freezing does **not** remove aggressive vacuums. Most tables still need them periodically, because only a vacuum that scans every page that might hold unfrozen XIDs can advance `relfrozenxid`. Eager freezing makes those vacuums cheaper. ## Misreadings to avoid - **The rate is not a freeze quota.** `vacuum_max_eager_freeze_failure_rate` limits how many eager attempts may fail; it does not say how much each vacuum must freeze. - **It does not make vacuums aggressive.** Forcing every vacuum to be aggressive is what `vacuum_freeze_table_age = 0` does; eager scanning stays inside normal vacuums. - **It is not in 17.** The feature, the setting and its storage parameter all arrived in 18, so on a 17 server the backlog behaves the old way. - **It does not touch the thresholds.** `vacuum_freeze_min_age`, `vacuum_freeze_table_age` and `autovacuum_freeze_max_age` keep their meanings and defaults. ## The two caps | Cap | Value | Configurable | Purpose | |---|---|---|---| | success cap | 20% of the all-visible but not all-frozen pages present when the vacuum starts | no, internal | spread freezing over several vacuums and limit waste on pages that change again | | failure cap | `vacuum_max_eager_freeze_failure_rate`, default `0.03` (3%) | yes, server-wide and as a per-table storage parameter | pause eager scanning when too many scanned pages could not be set all-frozen | The failure cap is applied per **region of 4,096 blocks** (32 MB at the default 8 kB block size): once a region exceeds its allowed failures, eager scanning is suspended until the next region. Only failures count against it. A value of `0` disables eager scanning; `1.0` lets it scan up to all the all-visible pages, still subject to the success cap. Aggressive vacuums are bound by neither cap. ## Tuning it for an ingest workload 1. **Append-only, never updated** (`readings`): eagerly frozen pages stay frozen, so the work is rarely wasted; a higher per-table rate lets eager scanning keep going through regions where some attempts fail, reaching more of the backlog per vacuum. 2. **Hot, frequently updated tables** (a `devices` registry storing last-seen timestamps): any change to a page clears its all-frozen bit, so eager freezes there are often undone; keeping the default or setting `0` avoids wasted reads and WAL. 3. **Loaded once, then static**: `COPY ... FREEZE` into a table created or truncated in the same transaction writes rows already frozen, so no backlog forms at all. ## Watching it work - `VACUUM (VERBOSE)` and autovacuum log lines report `pages: ... scanned (...% of total), N eagerly scanned`, along with how many pages and tuples were frozen. - PostgreSQL 18 adds **`pg_class.relallfrozen`**, the number of pages marked all-frozen in the visibility map. The gap between `relallvisible` and `relallfrozen` is roughly the backlog the next aggressive vacuum still faces. - `age(relfrozenxid)` still only resets when a vacuum scans every page that is not all-frozen; eager freezing shortens that scan rather than replacing it. On 17 and earlier none of this exists: the only levers were scheduling a manual `VACUUM (FREEZE)` at a quiet time or adjusting the freeze ages so the big pass lands when you choose.

  • When would you set vacuum_max_eager_freeze_failure_rate to 0 on a PostgreSQL 18 table?
    When pages are modified again soon after becoming all-visible. Any change clears the page's all-frozen bit, so eager freezes there are wasted reads and WAL. A devices table updated with last-seen timestamps is the example; an append-only readings table is the opposite case, where the default or a higher value pays off.
  • Besides eager freezing, how can a PostgreSQL bulk load avoid building a freeze backlog?
    `COPY ... FREEZE` writes rows already frozen, but only when the table was created or truncated in the same transaction (or subtransaction), with no older snapshots or open cursors, and not on a partitioned table. It suits loading a fresh staging table, not appending to a live one.

  • Eager freezing in PostgreSQL 18 removes the need for aggressive vacuums.
  • vacuum_max_eager_freeze_failure_rate is the share of pages each vacuum must freeze.
  • Normal vacuums before 18 already froze all-visible pages they skipped.
  • Eager freezing first shipped in PostgreSQL 17.
  • Raising vacuum_freeze_min_age makes rows get frozen sooner.

Assumes PostgreSQL 18: eager scanning, vacuum_max_eager_freeze_failure_rate and pg_class.relallfrozen are new in 18; 17 and earlier skip all-visible pages until an aggressive vacuum.