Skip to content

Commit 31a7e17

Browse files
Correct heap vacuum boundary state setup ordering
052026c mistakenly reordered setup steps in heap_vacuum_rel(), incorrectly moving RelationGetNumberOfBlocks() before vacuum_get_cutoffs(). OldestXmin must be determined before RelationGetNumberOfBlocks() calculates the number of blocks in the relation that will be vacuumed. Otherwise tuples older than OldestXmin may be inserted into the end of the relation into blocks that are not vacuumed. If additional tuples newer than those inserted into unscanned blocks but older than OldestXmin are inserted into free space earlier in the relation, the result could be advancing pg_class.relfrozenxid to a newer value than an unfrozen XID in one of the unscanned heap pages. Assigning an incorrect relfrozenxid can lead to data loss, so it is imperative that it correctly reflect the oldest unfrozen xid. Reported-by: Peter Geoghegan <pg@bowt.ie> Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/CAH2-WzntqvVEdbbpqG5JqSZGuLWmy4PBfUO-OswfivKchr2gvw%40mail.gmail.com
1 parent fc32be3 commit 31a7e17

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
757757
vacrel->vm_new_visible_pages = 0;
758758
vacrel->vm_new_visible_frozen_pages = 0;
759759
vacrel->vm_new_frozen_pages = 0;
760-
vacrel->rel_pages = orig_rel_pages = RelationGetNumberOfBlocks(rel);
761760

762761
/*
763762
* Get cutoffs that determine which deleted tuples are considered DEAD,
@@ -776,7 +775,9 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
776775
* to increase the number of dead tuples it can prune away.)
777776
*/
778777
vacrel->aggressive = vacuum_get_cutoffs(rel, params, &vacrel->cutoffs);
778+
vacrel->rel_pages = orig_rel_pages = RelationGetNumberOfBlocks(rel);
779779
vacrel->vistest = GlobalVisTestFor(rel);
780+
780781
/* Initialize state used to track oldest extant XID/MXID */
781782
vacrel->NewRelfrozenXid = vacrel->cutoffs.OldestXmin;
782783
vacrel->NewRelminMxid = vacrel->cutoffs.OldestMxact;

0 commit comments

Comments
 (0)