Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b132b9

Browse files
committed
Don't update relfrozenxid if any pages were skipped.
Vacuum recognizes that it can update relfrozenxid by checking whether it hasprocessed all pages of a relation. Unfortunately it performed that checkafter truncating the dead pages at the end of the relation, and used the newnumber of pages to decide whether all pages have been scanned. If the newnumber of pages happened to be smaller or equal to the number of pagesscanned, it incorrectly decided that all pages were scanned.This can lead to relfrozenxid being updated, even though some pages wereskipped that still contain old XIDs. That can lead to data loss due to xidwraparounds with some rows suddenly missing. This likely has escaped noticeso far because it takes a large number (~2^31) of xids being used to see theeffect, while a full-table vacuum before that would fix the issue.The incorrect logic was introduced by commitb4b6923. Backpatch this fix down to 8.4,like that commit.Andres Freund, with some modifications by me.
1 parent0cedfa7 commit0b132b9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
172172
intusecs;
173173
doubleread_rate,
174174
write_rate;
175-
boolscan_all;
175+
boolscan_all;/* should we scan all pages? */
176+
boolscanned_all;/* did we actually scan all pages? */
176177
TransactionIdfreezeTableLimit;
177178
BlockNumbernew_rel_pages;
178179
doublenew_rel_tuples;
@@ -217,6 +218,21 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
217218
/* Done with indexes */
218219
vac_close_indexes(nindexes,Irel,NoLock);
219220

221+
/*
222+
* Compute whether we actually scanned the whole relation. If we did, we
223+
* can adjust relfrozenxid.
224+
*
225+
* NB: We need to check this before truncating the relation, because that
226+
* will change ->rel_pages.
227+
*/
228+
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
229+
{
230+
Assert(!scan_all);
231+
scanned_all= false;
232+
}
233+
else
234+
scanned_all= true;
235+
220236
/*
221237
* Optionally truncate the relation.
222238
*
@@ -261,9 +277,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
261277
if (new_rel_allvisible>new_rel_pages)
262278
new_rel_allvisible=new_rel_pages;
263279

264-
new_frozen_xid=FreezeLimit;
265-
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
266-
new_frozen_xid=InvalidTransactionId;
280+
new_frozen_xid=scanned_all ?FreezeLimit :InvalidTransactionId;
267281

268282
vac_update_relstats(onerel,
269283
new_rel_pages,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp