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

Commit82b43f7

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 parent2390f2b commit82b43f7

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
178178
intusecs;
179179
doubleread_rate,
180180
write_rate;
181-
boolscan_all;
181+
boolscan_all;/* should we scan all pages? */
182+
boolscanned_all;/* did we actually scan all pages? */
182183
TransactionIdfreezeTableLimit;
183184
BlockNumbernew_rel_pages;
184185
doublenew_rel_tuples;
@@ -225,6 +226,21 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
225226
/* Done with indexes */
226227
vac_close_indexes(nindexes,Irel,NoLock);
227228

229+
/*
230+
* Compute whether we actually scanned the whole relation. If we did, we
231+
* can adjust relfrozenxid and relminmxid.
232+
*
233+
* NB: We need to check this before truncating the relation, because that
234+
* will change ->rel_pages.
235+
*/
236+
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
237+
{
238+
Assert(!scan_all);
239+
scanned_all= false;
240+
}
241+
else
242+
scanned_all= true;
243+
228244
/*
229245
* Optionally truncate the relation.
230246
*
@@ -254,8 +270,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
254270
* is all-visible we'd definitely like to know that. But clamp the value
255271
* to be not more than what we're setting relpages to.
256272
*
257-
* Also, don't change relfrozenxid if we skipped any pages, since then we
258-
* don't know for certain that all tuples have a newer xmin.
273+
* Also, don't change relfrozenxid/relminmxid if we skipped any pages,
274+
*since then wedon't know for certain that all tuples have a newer xmin.
259275
*/
260276
new_rel_pages=vacrelstats->rel_pages;
261277
new_rel_tuples=vacrelstats->new_rel_tuples;
@@ -269,13 +285,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
269285
if (new_rel_allvisible>new_rel_pages)
270286
new_rel_allvisible=new_rel_pages;
271287

272-
new_frozen_xid=FreezeLimit;
273-
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
274-
new_frozen_xid=InvalidTransactionId;
275-
276-
new_min_multi=MultiXactCutoff;
277-
if (vacrelstats->scanned_pages<vacrelstats->rel_pages)
278-
new_min_multi=InvalidMultiXactId;
288+
new_frozen_xid=scanned_all ?FreezeLimit :InvalidTransactionId;
289+
new_min_multi=scanned_all ?MultiXactCutoff :InvalidMultiXactId;
279290

280291
vac_update_relstats(onerel,
281292
new_rel_pages,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp