438
438
</para>
439
439
440
440
<para>
441
- <command>VACUUM</> normally skips pages that don't have any dead row
442
- versions, but those pages might still have row versions with old XID
443
- values. To ensure all old row versions have been frozen, a
444
- scan of the whole table is needed.
445
- <xref linkend="guc-vacuum-freeze-table-age"> controls when
446
- <command>VACUUM</> does that: a whole table sweep is forced if
447
- the table hasn't been fully scanned for <varname>vacuum_freeze_table_age</>
448
- minus <varname>vacuum_freeze_min_age</> transactions. Setting it to 0
449
- forces <command>VACUUM</> to always scan all pages, effectively ignoring
450
- the visibility map.
441
+ <command>VACUUM</> uses the <link linkend="storage-vm">visibility map</>
442
+ to determine which pages of a relation must be scanned. Normally, it
443
+ will skips pages that don't have any dead row versions even if those pages
444
+ might still have row versions with old XID values. Therefore, normal
445
+ scans won't succeed in freezing every row version in the table.
446
+ Periodically, <command>VACUUM</> will perform an <firstterm>aggressive
447
+ vacuum</>, skipping only those pages which contain neither dead rows nor
448
+ any unfrozen XID or MXID values.
449
+ <xref linkend="guc-vacuum-freeze-table-age">
450
+ controls when <command>VACUUM</> does that: all-visible but not all-frozen
451
+ pages are scanned if the number of transactions that have passed since the
452
+ last such scan is greater than <varname>vacuum_freeze_table_age</> minus
453
+ <varname>vacuum_freeze_min_age</>. Setting
454
+ <varname>vacuum_freeze_table_age</> to 0 forces <command>VACUUM</> to
455
+ use this more aggressive strategy for all scans.
451
456
</para>
452
457
453
458
<para>
454
459
The maximum time that a table can go unvacuumed is two billion
455
460
transactions minus the <varname>vacuum_freeze_min_age</> value at
456
- the time <command>VACUUM</> last scanned the whole table. If it were to go
461
+ the time of the last aggressive vacuum. If it were to go
457
462
unvacuumed for longer than
458
463
that, data loss could result. To ensure that this does not happen,
459
464
autovacuum is invoked on any table that might contain unfrozen rows with
491
496
normal delete and update activity is run in that window. Setting it too
492
497
close could lead to anti-wraparound autovacuums, even though the table
493
498
was recently vacuumed to reclaim space, whereas lower values lead to more
494
- frequent whole-table scans .
499
+ frequent aggressive vacuuming .
495
500
</para>
496
501
497
502
<para>
527
532
<structname>pg_database</>. In particular,
528
533
the <structfield>relfrozenxid</> column of a table's
529
534
<structname>pg_class</> row contains the freeze cutoff XID that was used
530
- by the last whole-table <command>VACUUM</> for that table. All rows
535
+ by the last aggressive <command>VACUUM</> for that table. All rows
531
536
inserted by transactions with XIDs older than this cutoff XID are
532
537
guaranteed to have been frozen. Similarly,
533
538
the <structfield>datfrozenxid</> column of a database's
@@ -552,20 +557,23 @@ SELECT datname, age(datfrozenxid) FROM pg_database;
552
557
</para>
553
558
554
559
<para>
555
- <command>VACUUM</> normally
556
- only scans pages that have been modified since the last vacuum, but
557
- <structfield>relfrozenxid</> can only be advanced when the whole table is
558
- scanned. The whole table is scanned when <structfield>relfrozenxid</> is
559
- more than <varname>vacuum_freeze_table_age</> transactions old, when
560
- <command>VACUUM</>'s <literal>FREEZE</> option is used, or when all pages
561
- happen to
560
+ <command>VACUUM</> normally only scans pages that have been modified
561
+ since the last vacuum, but <structfield>relfrozenxid</> can only be
562
+ advanced when every page of the table
563
+ that might contain unfrozen XIDs is scanned. This happens when
564
+ <structfield>relfrozenxid</> is more than
565
+ <varname>vacuum_freeze_table_age</> transactions old, when
566
+ <command>VACUUM</>'s <literal>FREEZE</> option is used, or when all
567
+ pages that are not already all-frozen happen to
562
568
require vacuuming to remove dead row versions. When <command>VACUUM</>
563
- scans the whole table, after it's finished <literal>age(relfrozenxid)</>
564
- should be a little more than the <varname>vacuum_freeze_min_age</> setting
565
- that was used (more by the number of transactions started since the
566
- <command>VACUUM</> started). If no whole-table-scanning <command>VACUUM</>
567
- is issued on the table until <varname>autovacuum_freeze_max_age</> is
568
- reached, an autovacuum will soon be forced for the table.
569
+ scans every page in the table that is not already all-frozen, it should
570
+ set <literal>age(relfrozenxid)</> to a value just a little more than the
571
+ <varname>vacuum_freeze_min_age</> setting
572
+ that was used (more by the number of transcations started since the
573
+ <command>VACUUM</> started). If no <structfield>relfrozenxid</>-advancing
574
+ <command>VACUUM</> is issued on the table until
575
+ <varname>autovacuum_freeze_max_age</> is reached, an autovacuum will soon
576
+ be forced for the table.
569
577
</para>
570
578
571
579
<para>
@@ -634,35 +642,37 @@ HINT: Stop the postmaster and vacuum that database in single-user mode.
634
642
</para>
635
643
636
644
<para>
637
- During a <command>VACUUM</> table scan, either partial or of the whole
638
- table, any multixact ID older than
645
+ Whenever <command>VACUUM</> scans any part of a table, it will replace
646
+ any multixact ID it encounters which is older than
639
647
<xref linkend="guc-vacuum-multixact-freeze-min-age">
640
- is replaced by a different value, which can be the zero value, a single
648
+ by a different value, which can be the zero value, a single
641
649
transaction ID, or a newer multixact ID. For each table,
642
650
<structname>pg_class</>.<structfield>relminmxid</> stores the oldest
643
651
possible multixact ID still appearing in any tuple of that table.
644
652
If this value is older than
645
- <xref linkend="guc-vacuum-multixact-freeze-table-age">, a whole-table
646
- scan is forced. <function>mxid_age()</> can be used on
653
+ <xref linkend="guc-vacuum-multixact-freeze-table-age">, an aggressive
654
+ vacuum is forced. As discussed in the previous section, an aggressive
655
+ vacuum means that only those pages which are known to be all-frozen will
656
+ be skipped. <function>mxid_age()</> can be used on
647
657
<structname>pg_class</>.<structfield>relminmxid</> to find its age.
648
658
</para>
649
659
650
660
<para>
651
- Whole-table <command>VACUUM</> scans, regardless of
661
+ Aggressive <command>VACUUM</> scans, regardless of
652
662
what causes them, enable advancing the value for that table.
653
663
Eventually, as all tables in all databases are scanned and their
654
664
oldest multixact values are advanced, on-disk storage for older
655
665
multixacts can be removed.
656
666
</para>
657
667
658
668
<para>
659
- As a safety device, a whole-table vacuum scan will occur for any table
669
+ As a safety device, an aggressive vacuum scan will occur for any table
660
670
whose multixact-age is greater than
661
- <xref linkend="guc-autovacuum-multixact-freeze-max-age">. Whole-table
671
+ <xref linkend="guc-autovacuum-multixact-freeze-max-age">. Aggressive
662
672
vacuum scans will also occur progressively for all tables, starting with
663
673
those that have the oldest multixact-age, if the amount of used member
664
674
storage space exceeds the amount 50% of the addressable storage space.
665
- Both of these kinds of whole-table scans will occur even if autovacuum is
675
+ Both of these kinds of aggressive scans will occur even if autovacuum is
666
676
nominally disabled.
667
677
</para>
668
678
</sect3>
@@ -743,9 +753,9 @@ vacuum threshold = vacuum base threshold + vacuum scale factor * number of tuple
743
753
<command>UPDATE</command> and <command>DELETE</command> operation. (It
744
754
is only semi-accurate because some information might be lost under heavy
745
755
load.) If the <structfield>relfrozenxid</> value of the table is more
746
- than <varname>vacuum_freeze_table_age</> transactions old, the whole
747
- table is scanned to freeze old tuples and advance
748
- <structfield>relfrozenxid</>, otherwise only pages that have been modified
756
+ than <varname>vacuum_freeze_table_age</> transactions old, an aggressive
757
+ vacuum is performed to freeze old tuples and advance
758
+ <structfield>relfrozenxid</>; otherwise, only pages that have been modified
749
759
since the last vacuum are scanned.
750
760
</para>
751
761
0 commit comments