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

Commitf222349

Browse files
committed
Close race condition between datfrozen and relfrozen updates.
vac_update_datfrozenxid() did multiple loads of relfrozenxid andrelminmxid from buffer memory, and it assumed each would get the samevalue. Not so if a concurrent vac_update_relstats() did an inplaceupdate. Commit2d2e40e fixed the samekind of bug in vac_truncate_clog(). Today's bug could cause therel-level field and XIDs in the rel's rows to precede the db-levelfield. A cluster having such values should VACUUM affected tables.Back-patch to v12 (all supported versions).Discussion:https://postgr.es/m/20240423003956.e7.nmisch@google.com
1 parentcb0ccef commitf222349

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

‎src/backend/commands/vacuum.c‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,8 @@ vac_update_datfrozenxid(void)
13301330
/*
13311331
* We must seqscan pg_class to find the minimum Xid, because there is no
13321332
* index that can help us here.
1333+
*
1334+
* See vac_truncate_clog() for the race condition to prevent.
13331335
*/
13341336
relation=table_open(RelationRelationId,AccessShareLock);
13351337

@@ -1338,7 +1340,9 @@ vac_update_datfrozenxid(void)
13381340

13391341
while ((classTup=systable_getnext(scan))!=NULL)
13401342
{
1341-
Form_pg_classclassForm= (Form_pg_class)GETSTRUCT(classTup);
1343+
volatileFormData_pg_class*classForm= (Form_pg_class)GETSTRUCT(classTup);
1344+
TransactionIdrelfrozenxid=classForm->relfrozenxid;
1345+
TransactionIdrelminmxid=classForm->relminmxid;
13421346

13431347
/*
13441348
* Only consider relations able to hold unfrozen XIDs (anything else
@@ -1348,8 +1352,8 @@ vac_update_datfrozenxid(void)
13481352
classForm->relkind!=RELKIND_MATVIEW&&
13491353
classForm->relkind!=RELKIND_TOASTVALUE)
13501354
{
1351-
Assert(!TransactionIdIsValid(classForm->relfrozenxid));
1352-
Assert(!MultiXactIdIsValid(classForm->relminmxid));
1355+
Assert(!TransactionIdIsValid(relfrozenxid));
1356+
Assert(!MultiXactIdIsValid(relminmxid));
13531357
continue;
13541358
}
13551359

@@ -1368,34 +1372,34 @@ vac_update_datfrozenxid(void)
13681372
* before those relations have been scanned and cleaned up.
13691373
*/
13701374

1371-
if (TransactionIdIsValid(classForm->relfrozenxid))
1375+
if (TransactionIdIsValid(relfrozenxid))
13721376
{
1373-
Assert(TransactionIdIsNormal(classForm->relfrozenxid));
1377+
Assert(TransactionIdIsNormal(relfrozenxid));
13741378

13751379
/* check for values in the future */
1376-
if (TransactionIdPrecedes(lastSaneFrozenXid,classForm->relfrozenxid))
1380+
if (TransactionIdPrecedes(lastSaneFrozenXid,relfrozenxid))
13771381
{
13781382
bogus= true;
13791383
break;
13801384
}
13811385

13821386
/* determine new horizon */
1383-
if (TransactionIdPrecedes(classForm->relfrozenxid,newFrozenXid))
1384-
newFrozenXid=classForm->relfrozenxid;
1387+
if (TransactionIdPrecedes(relfrozenxid,newFrozenXid))
1388+
newFrozenXid=relfrozenxid;
13851389
}
13861390

1387-
if (MultiXactIdIsValid(classForm->relminmxid))
1391+
if (MultiXactIdIsValid(relminmxid))
13881392
{
13891393
/* check for values in the future */
1390-
if (MultiXactIdPrecedes(lastSaneMinMulti,classForm->relminmxid))
1394+
if (MultiXactIdPrecedes(lastSaneMinMulti,relminmxid))
13911395
{
13921396
bogus= true;
13931397
break;
13941398
}
13951399

13961400
/* determine new horizon */
1397-
if (MultiXactIdPrecedes(classForm->relminmxid,newMinMulti))
1398-
newMinMulti=classForm->relminmxid;
1401+
if (MultiXactIdPrecedes(relminmxid,newMinMulti))
1402+
newMinMulti=relminmxid;
13991403
}
14001404
}
14011405

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp