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

Commitf0d72ef

Browse files
committed
Clean up after erroneous SELECT FOR UPDATE/SHARE on a sequence.
My previous commit disallowed this operation, but did nothing aboutcleaning up the damage if one had already been done. With the operationdisallowed, it's okay to just forcibly clear xmax in a sequence's tuple,since any value seen there could not represent a live transaction's lock.So, any sequence-specific operation will repair the problem automatically,whether or not the user has already seen "could not access status oftransaction" failures.
1 parenta12899e commitf0d72ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎src/backend/commands/sequence.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,22 @@ read_info(SeqTable elm, Relation rel, Buffer *buf)
950950
Assert(ItemIdIsUsed(lp));
951951
tuple.t_data= (HeapTupleHeader)PageGetItem((Page)page,lp);
952952

953+
/*
954+
* Previous releases of Postgres neglected to prevent SELECT FOR UPDATE
955+
* on a sequence, which would leave a non-frozen XID in the sequence
956+
* tuple's xmax, which eventually leads to clog access failures or worse.
957+
* If we see this has happened, clean up after it. We treat this like a
958+
* hint bit update, ie, don't bother to WAL-log it, since we can certainly
959+
* do this again if the update gets lost.
960+
*/
961+
if (HeapTupleHeaderGetXmax(tuple.t_data)!=InvalidTransactionId)
962+
{
963+
HeapTupleHeaderSetXmax(tuple.t_data,InvalidTransactionId);
964+
tuple.t_data->t_infomask &= ~HEAP_XMAX_COMMITTED;
965+
tuple.t_data->t_infomask |=HEAP_XMAX_INVALID;
966+
SetBufferCommitInfoNeedsSave(*buf);
967+
}
968+
953969
seq= (Form_pg_sequence)GETSTRUCT(&tuple);
954970

955971
elm->increment=seq->increment_by;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp