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

Commit244413f

Browse files
committed
Add missing buffer lock acquisition in GetTupleForTrigger().
If we had not been holding buffer pin continuously since the tuple wasinitially fetched by the UPDATE or DELETE query, it would be possible forVACUUM or a page-prune operation to move the tuple while we're trying tocopy it. This would result in a garbage "old" tuple value being passed toan AFTER ROW UPDATE or AFTER ROW DELETE trigger. The preconditions forthis are somewhat improbable, and the timing constraints are very tight;so it's not so surprising that this hasn't been reported from the field,even though the bug has been there a long time.Problem found by Andres Freund. Back-patch to all active branches.
1 parent9837be9 commit244413f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎src/backend/commands/trigger.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,16 @@ ltrmark:;
21442144

21452145
buffer=ReadBuffer(relation,ItemPointerGetBlockNumber(tid));
21462146

2147+
/*
2148+
* Although we already know this tuple is valid, we must lock the
2149+
* buffer to ensure that no one has a buffer cleanup lock; otherwise
2150+
* they might move the tuple while we try to copy it. But we can
2151+
* release the lock before actually doing the heap_copytuple call,
2152+
* since holding pin is sufficient to prevent anyone from getting a
2153+
* cleanup lock they don't already hold.
2154+
*/
2155+
LockBuffer(buffer,BUFFER_LOCK_SHARE);
2156+
21472157
dp= (PageHeader)BufferGetPage(buffer);
21482158
lp=PageGetItemId(dp,ItemPointerGetOffsetNumber(tid));
21492159

@@ -2153,6 +2163,8 @@ ltrmark:;
21532163
tuple.t_len=ItemIdGetLength(lp);
21542164
tuple.t_self=*tid;
21552165
tuple.t_tableOid=RelationGetRelid(relation);
2166+
2167+
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
21562168
}
21572169

21582170
result=heap_copytuple(&tuple);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp