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

Commitfbcf4b9

Browse files
committed
Fix possible "tuple concurrently updated" error in ALTER TABLE.
When adding an inheritance parent to a table, an AccessShareLock on theparent isn't strong enough to prevent trouble, so takeShareUpdateExclusiveLock instead. Since this is a behavior change,albeit a fairly unobtrusive one, and since we have only one reportfrom the field, no back-patch.Report by Jon Nelson, analysis by Alvaro Herrera, fix by me.
1 parent7275899 commitfbcf4b9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,14 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
13451345
AttrNumber*newattno;
13461346
AttrNumberparent_attno;
13471347

1348-
relation=heap_openrv(parent,AccessShareLock);
1348+
/*
1349+
* A self-exclusive lock is needed here. If two backends attempt to
1350+
* add children to the same parent simultaneously, and that parent has
1351+
* no pre-existing children, then both will attempt to update the
1352+
* parent's relhassubclass field, leading to a "tuple concurrently
1353+
* updated" error.
1354+
*/
1355+
relation=heap_openrv(parent,ShareUpdateExclusiveLock);
13491356

13501357
if (relation->rd_rel->relkind!=RELKIND_RELATION)
13511358
ereport(ERROR,
@@ -7942,10 +7949,10 @@ ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
79427949
List*children;
79437950

79447951
/*
7945-
*AccessShareLock on the parentiswhat's obtained during normal CREATE
7946-
*TABLE ... INHERITS ..., so should be enough here.
7952+
*A self-exclusive lockisneeded here. See the similar case in
7953+
*MergeAttributes() for a full explanation.
79477954
*/
7948-
parent_rel=heap_openrv(parent,AccessShareLock);
7955+
parent_rel=heap_openrv(parent,ShareUpdateExclusiveLock);
79497956

79507957
/*
79517958
* Must be owner of both parent and child -- child was checked by

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp