Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b018fa

Browse files
Set relfrozenxid to oldest extant XID seen by VACUUM.
When VACUUM set relfrozenxid before now, it set it to whatever value was used to determine which tuples to freeze -- the FreezeLimit cutoff. This approach was very naive. The relfrozenxid invariant only requires that new relfrozenxid values be <= the oldest extant XID remaining in the table (at the point that the VACUUM operation ends), which in general might be much more recent than FreezeLimit. VACUUM now carefully tracks the oldest remaining XID/MultiXactId as it goes (the oldest remaining values _after_ lazy_scan_prune processing). The final values are set as the table's new relfrozenxid and new relminmxid in pg_class at the end of each VACUUM. The oldest XID might come from a tuple's xmin, xmax, or xvac fields. It might even come from one of the table's remaining MultiXacts. Final relfrozenxid values must still be >= FreezeLimit in an aggressive VACUUM (FreezeLimit still acts as a lower bound on the final value that aggressive VACUUM can set relfrozenxid to). Since standard VACUUMs still make no guarantees about advancing relfrozenxid, they might as well set relfrozenxid to a value from well before FreezeLimit when the opportunity presents itself. In general standard VACUUMs may now set relfrozenxid to any value > the original relfrozenxid and <= OldestXmin. Credit for the general idea of using the oldest extant XID to set pg_class.relfrozenxid at the end of VACUUM goes to Andres Freund. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Andres Freund <andres@anarazel.de> Reviewed-By: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/CAH2-WzkymFbz6D_vL+jmqSn_5q1wsFvFrE+37yLgL_Rkfd6Gzg@mail.gmail.com
1 parent 05023a2 commit 0b018fa

File tree

13 files changed

+717
-305
lines changed

13 files changed

+717
-305
lines changed

doc/src/sgml/maintenance.sgml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,11 @@
586586
statistics in the system tables <structname>pg_class</structname> and
587587
<structname>pg_database</structname>. In particular,
588588
the <structfield>relfrozenxid</structfield> column of a table's
589-
<structname>pg_class</structname> row contains the freeze cutoff XID that was used
590-
by the last aggressive <command>VACUUM</command> for that table. All rows
591-
inserted by transactions with XIDs older than this cutoff XID are
592-
guaranteed to have been frozen. Similarly,
593-
the <structfield>datfrozenxid</structfield> column of a database's
589+
<structname>pg_class</structname> row contains the oldest remaining unfrozen
590+
XID at the end of the most recent <command>VACUUM</command> that successfully
591+
advanced <structfield>relfrozenxid</structfield> (typically the most recent
592+
aggressive VACUUM). Similarly, the
593+
<structfield>datfrozenxid</structfield> column of a database's
594594
<structname>pg_database</structname> row is a lower bound on the unfrozen XIDs
595595
appearing in that database &mdash; it is just the minimum of the
596596
per-table <structfield>relfrozenxid</structfield> values within the database.
@@ -638,7 +638,11 @@ SELECT datname, age(datfrozenxid) FROM pg_database;
638638
set <literal>age(relfrozenxid)</literal> to a value just a little more than the
639639
<varname>vacuum_freeze_min_age</varname> setting
640640
that was used (more by the number of transactions started since the
641-
<command>VACUUM</command> started). If no <structfield>relfrozenxid</structfield>-advancing
641+
<command>VACUUM</command> started). <command>VACUUM</command>
642+
will set <structfield>relfrozenxid</structfield> to the oldest XID
643+
that remains in the table, so it's possible that the final value
644+
will be much more recent than strictly required.
645+
If no <structfield>relfrozenxid</structfield>-advancing
642646
<command>VACUUM</command> is issued on the table until
643647
<varname>autovacuum_freeze_max_age</varname> is reached, an autovacuum will soon
644648
be forced for the table.

0 commit comments

Comments
 (0)