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

Commitbf0d21e

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 parent9a1c6dd commitbf0d21e

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
@@ -166,7 +166,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
166166
BlockNumberpossibly_freeable;
167167
PGRUsageru0;
168168
TimestampTzstarttime=0;
169-
boolscan_all;
169+
boolscan_all;/* should we scan all pages? */
170+
boolscanned_all;/* did we actually scan all pages? */
170171
TransactionIdfreezeTableLimit;
171172
BlockNumbernew_rel_pages;
172173
doublenew_rel_tuples;
@@ -209,6 +210,21 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
209210
/* Done with indexes */
210211
vac_close_indexes(nindexes,Irel,NoLock);
211212

213+
/*
214+
* Compute whether we actually scanned the whole relation. If we did, we
215+
* can adjust relfrozenxid.
216+
*
217+
* NB: We need to check this before truncating the relation, because that
218+
* will change ->rel_pages.
219+
*/
220+
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
221+
{
222+
Assert(!scan_all);
223+
scanned_all= false;
224+
}
225+
else
226+
scanned_all= true;
227+
212228
/*
213229
* Optionally truncate the relation.
214230
*
@@ -245,9 +261,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
245261
new_rel_tuples=vacrelstats->old_rel_tuples;
246262
}
247263

248-
new_frozen_xid=FreezeLimit;
249-
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
250-
new_frozen_xid=InvalidTransactionId;
264+
new_frozen_xid=scanned_all ?FreezeLimit :InvalidTransactionId;
251265

252266
vac_update_relstats(onerel,
253267
new_rel_pages,new_rel_tuples,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp