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

Commitc0ee694

Browse files
committed
Avoid using tuple from syscache for update of pg_database.datfrozenxid
pg_database.datfrozenxid gets updated using an in-place update at theend of vacuum or autovacuum. Since96cdeae, as pg_database has a toastrelation, it is possible for a pg_database tuple to have toast valuesif there is a large set of ACLs in place. In such a case, the in-placeupdate would fail because of the flattening of the toast values done forthe catcache entry fetched. Instead of using a copy from the catcache,this changes the logic to fetch the copy of the tuple by directlyscanning pg_database.Note that before96cdeae, attempting to insert such a tuple topg_database would cause a "row is too big" error, so the end-of-vacuumproblem was not reachable.This issue has been originally fixed in947789f on v14~, and there havebeen reports about this problem on v12 and v13, causing failures at theend of VACUUM. This completes the fix on all the stable branches wherepg_database can use a toast table, down to 12.Author: Ashwin Agrawal, Junfeng YangDiscussion:https://postgr.es/m/DM5PR0501MB38800D9E4605BCA72DD35557CCE10@DM5PR0501MB3880.namprd05.prod.outlook.comDiscussion:https://postgr.es/m/Y70XNVbUWQsR2Car@paquier.xyzBackpatch-through: 12
1 parent274185d commitc0ee694

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5837,6 +5837,10 @@ heap_abort_speculative(Relation relation, ItemPointer tid)
58375837
*
58385838
* tuple is an in-memory tuple structure containing the data to be written
58395839
* over the target tuple. Also, tuple->t_self identifies the target tuple.
5840+
*
5841+
* Note that the tuple updated here had better not come directly from the
5842+
* syscache if the relation has a toast relation as this tuple could
5843+
* include toast values that have been expanded, causing a failure here.
58405844
*/
58415845
void
58425846
heap_inplace_update(Relationrelation,HeapTupletuple)

‎src/backend/commands/vacuum.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include"access/tableam.h"
3232
#include"access/transam.h"
3333
#include"access/xact.h"
34+
#include"catalog/indexing.h"
3435
#include"catalog/namespace.h"
3536
#include"catalog/pg_database.h"
3637
#include"catalog/pg_inherits.h"
@@ -1294,6 +1295,7 @@ vac_update_datfrozenxid(void)
12941295
MultiXactIdlastSaneMinMulti;
12951296
boolbogus= false;
12961297
booldirty= false;
1298+
ScanKeyDatakey[1];
12971299

12981300
/*
12991301
* Restrict this task to one backend per database. This avoids race
@@ -1411,10 +1413,25 @@ vac_update_datfrozenxid(void)
14111413
/* Now fetch the pg_database tuple we need to update. */
14121414
relation=table_open(DatabaseRelationId,RowExclusiveLock);
14131415

1414-
/* Fetch a copy of the tuple to scribble on */
1415-
tuple=SearchSysCacheCopy1(DATABASEOID,ObjectIdGetDatum(MyDatabaseId));
1416+
/*
1417+
* Get the pg_database tuple to scribble on. Note that this does not
1418+
* directly rely on the syscache to avoid issues with flattened toast
1419+
* values for the in-place update.
1420+
*/
1421+
ScanKeyInit(&key[0],
1422+
Anum_pg_database_oid,
1423+
BTEqualStrategyNumber,F_OIDEQ,
1424+
ObjectIdGetDatum(MyDatabaseId));
1425+
1426+
scan=systable_beginscan(relation,DatabaseOidIndexId, true,
1427+
NULL,1,key);
1428+
tuple=systable_getnext(scan);
1429+
tuple=heap_copytuple(tuple);
1430+
systable_endscan(scan);
1431+
14161432
if (!HeapTupleIsValid(tuple))
14171433
elog(ERROR,"could not find tuple for database %u",MyDatabaseId);
1434+
14181435
dbform= (Form_pg_database)GETSTRUCT(tuple);
14191436

14201437
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp