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

Commit5ed74d8

Browse files
committed
Fix corruption of toast indexes with REINDEX CONCURRENTLY
REINDEX CONCURRENTLY run on a toast index or a toast relation couldcorrupt the target indexes rebuilt, as a backend running in parallelthat manipulates toast values would directly release the lock on thetoast relation when its local operation is done, rather than releasingthe lock once the transaction that manipulated the toast valuescommitted.The fix done here is simple: we now hold a ROW EXCLUSIVE lock on thetoast relation when saving or deleting a toast value until thetransaction working on them is committed, so as a concurrent reindexhappening in parallel would be able to wait for any activity and see anynew rows inserted (or deleted).An isolation test is added to check after the case fixed here, which isa bit fancy by design as it relies on allow_system_table_mods to renamethe toast table and its index to fixed names. This way, it is possibleto reindex them directly without any dependency on the OID of theunderlying relation. Note that this could not use a DO block either, asREINDEX CONCURRENTLY cannot be run in a transaction block. The test isbackpatched down to 13, where it is possible, thanks toc4a7a39, to useallow_system_table_mods in a test suite.Reported-by: Alexey ErmakovAnalyzed-by: Andres Freund, Noah MischAuthor: Michael PaquierReviewed-by: Nathan BossartDiscussion:https://postgr.es/m/17268-d2fb426e0895abd4@postgresql.orgBackpatch-through: 12
1 parent8de159c commit5ed74d8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,10 +1709,12 @@ toast_save_datum(Relation rel, Datum value,
17091709
}
17101710

17111711
/*
1712-
* Done - close toast relation and its indexes
1712+
* Done - close toast relation and its indexes but keep the lock until
1713+
* commit, so as a concurrent reindex done directly on the toast relation
1714+
* would be able to wait for this transaction.
17131715
*/
1714-
toast_close_indexes(toastidxs,num_indexes,RowExclusiveLock);
1715-
table_close(toastrel,RowExclusiveLock);
1716+
toast_close_indexes(toastidxs,num_indexes,NoLock);
1717+
table_close(toastrel,NoLock);
17161718

17171719
/*
17181720
* Create the TOAST pointer value that we'll return
@@ -1790,11 +1792,13 @@ toast_delete_datum(Relation rel, Datum value, bool is_speculative)
17901792
}
17911793

17921794
/*
1793-
* End scan and close relations
1795+
* End scan and close relations but keep the lock until commit, so as a
1796+
* concurrent reindex done directly on the toast relation would be able to
1797+
* wait for this transaction.
17941798
*/
17951799
systable_endscan_ordered(toastscan);
1796-
toast_close_indexes(toastidxs,num_indexes,RowExclusiveLock);
1797-
table_close(toastrel,RowExclusiveLock);
1800+
toast_close_indexes(toastidxs,num_indexes,NoLock);
1801+
table_close(toastrel,NoLock);
17981802
}
17991803

18001804

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp