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

Commit70cadfb

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 parent440b625 commit70cadfb

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
@@ -1379,6 +1379,8 @@ vac_update_datfrozenxid(void)
13791379
/*
13801380
* We must seqscan pg_class to find the minimum Xid, because there is no
13811381
* index that can help us here.
1382+
*
1383+
* See vac_truncate_clog() for the race condition to prevent.
13821384
*/
13831385
relation=table_open(RelationRelationId,AccessShareLock);
13841386

@@ -1387,7 +1389,9 @@ vac_update_datfrozenxid(void)
13871389

13881390
while ((classTup=systable_getnext(scan))!=NULL)
13891391
{
1390-
Form_pg_classclassForm= (Form_pg_class)GETSTRUCT(classTup);
1392+
volatileFormData_pg_class*classForm= (Form_pg_class)GETSTRUCT(classTup);
1393+
TransactionIdrelfrozenxid=classForm->relfrozenxid;
1394+
TransactionIdrelminmxid=classForm->relminmxid;
13911395

13921396
/*
13931397
* Only consider relations able to hold unfrozen XIDs (anything else
@@ -1397,8 +1401,8 @@ vac_update_datfrozenxid(void)
13971401
classForm->relkind!=RELKIND_MATVIEW&&
13981402
classForm->relkind!=RELKIND_TOASTVALUE)
13991403
{
1400-
Assert(!TransactionIdIsValid(classForm->relfrozenxid));
1401-
Assert(!MultiXactIdIsValid(classForm->relminmxid));
1404+
Assert(!TransactionIdIsValid(relfrozenxid));
1405+
Assert(!MultiXactIdIsValid(relminmxid));
14021406
continue;
14031407
}
14041408

@@ -1417,34 +1421,34 @@ vac_update_datfrozenxid(void)
14171421
* before those relations have been scanned and cleaned up.
14181422
*/
14191423

1420-
if (TransactionIdIsValid(classForm->relfrozenxid))
1424+
if (TransactionIdIsValid(relfrozenxid))
14211425
{
1422-
Assert(TransactionIdIsNormal(classForm->relfrozenxid));
1426+
Assert(TransactionIdIsNormal(relfrozenxid));
14231427

14241428
/* check for values in the future */
1425-
if (TransactionIdPrecedes(lastSaneFrozenXid,classForm->relfrozenxid))
1429+
if (TransactionIdPrecedes(lastSaneFrozenXid,relfrozenxid))
14261430
{
14271431
bogus= true;
14281432
break;
14291433
}
14301434

14311435
/* determine new horizon */
1432-
if (TransactionIdPrecedes(classForm->relfrozenxid,newFrozenXid))
1433-
newFrozenXid=classForm->relfrozenxid;
1436+
if (TransactionIdPrecedes(relfrozenxid,newFrozenXid))
1437+
newFrozenXid=relfrozenxid;
14341438
}
14351439

1436-
if (MultiXactIdIsValid(classForm->relminmxid))
1440+
if (MultiXactIdIsValid(relminmxid))
14371441
{
14381442
/* check for values in the future */
1439-
if (MultiXactIdPrecedes(lastSaneMinMulti,classForm->relminmxid))
1443+
if (MultiXactIdPrecedes(lastSaneMinMulti,relminmxid))
14401444
{
14411445
bogus= true;
14421446
break;
14431447
}
14441448

14451449
/* determine new horizon */
1446-
if (MultiXactIdPrecedes(classForm->relminmxid,newMinMulti))
1447-
newMinMulti=classForm->relminmxid;
1450+
if (MultiXactIdPrecedes(relminmxid,newMinMulti))
1451+
newMinMulti=relminmxid;
14481452
}
14491453
}
14501454

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp