Re: BUG #17268: Possible corruption in toast index after reindex index concurrently
Nathan Bossart <bossartn@amazon.com>
From: "Bossart, Nathan" <bossartn@amazon.com>
To: Michael Paquier <michael@paquier.xyz>, Noah Misch <noah@leadboat.com>
Cc: Andres Freund <andres@anarazel.de>, Alexey Ermakov <alexey.ermakov@dataegret.com>, Robert Haas <robertmhaas@gmail.com>, "Maxim
Boguk" <maxim.boguk@gmail.com>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>, Peter Geoghegan <pg@bowt.ie>
Date: 2021-12-07T22:04:54Z
Lists: pgsql-bugs
On 12/5/21, 5:54 PM, "Michael Paquier" <michael@paquier.xyz> wrote: > I have been working on this one again for the last couple of days, and > I would still go with the simple solution, releasing the row-level > toast locks only at the end of the transaction when saving and > deleting a toast value. While testing, I have noticed that the > deletion part is also important, as a REINDEX CONCURRENTLY run in > parallel of a transaction removing a toast value would go through > without that, rather than waiting for the transaction doing the > deletion to commit first. I have expanded the tests with everything I > could think about, so I'd like to commit the attached. The test is > fancy with its use of allow_system_table_mods to make the toast > relation names reliable, but it has been really useful. I confirmed that the new tests reliably produce corruption and that the suggested fix resolves it. I also lean towards the simple solution, but I do wonder if it creates any interesting side effects. For example, could holding the locks longer impact performance? (Of course, performance is probably not a great reason to avoid a sustainable solution.) - toast_close_indexes(toastidxs, num_indexes, RowExclusiveLock); - table_close(toastrel, RowExclusiveLock); + toast_close_indexes(toastidxs, num_indexes, NoLock); + table_close(toastrel, NoLock); I think it would be good to expand the comments above these changes to explain why we are keeping the lock. That might help avoid similar problems in the future. Nathan
Commits
-
Fix corruption of toast indexes with REINDEX CONCURRENTLY
- 5ed74d874f49 12.10 landed
- 9acea52ea3d4 13.6 landed
- 64ab21f0e5de 14.2 landed
- f99870dd8673 15.0 landed