Re: v12.0: reindex CONCURRENTLY: lock ShareUpdateExclusiveLock on object 14185/39327/0 is already held
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: pgsql-hackers@lists.postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, Andreas Karlsson <andreas@proxel.se>
Date: 2019-10-24T02:42:04Z
Lists: pgsql-hackers
Attachments
- reindex_conc_interrupts.patch (text/x-diff) patch
On Wed, Oct 23, 2019 at 07:18:33PM +0900, Michael Paquier wrote: > I can confirm that this is an issue related to session locks which are > not cleaned up when in an out-of-transaction state, state that can be > reached between a transaction commit or start while holding at least > one session lock within one single command of VACUUM, CIC or REINDEX > CONCURRENTLY. Please let me back-pedal a bit on this one after sleeping on it. Actually, if you look at CIC and VACUUM, those code paths are much more careful regarding the position of CHECK_FOR_INTERRUPTS() than REINDEX CONCURRENTLY is in the fact that they happen only within a transaction context. In the case of REINDEX CONCURRENTLY and the failure reported here, the current code is careless: it depends of course on the timing of statement_timeout, but session locks would remain behind when hitting an interruption at the beginning of phase 2 or 3 in indexcmds.c. So the answer is simple: by moving the interrupt checks within a transaction context, the problem gets solved. This also fixes a second issue as the original code would cause xact.c to generate some useless warnings. Please see the attached. Justin, does it fix your problems regarding the locks? For me it does. > The failure is actually pretty easy to reproduce if you > add an elog(ERROR) after a CommitTransactionCommand() call and then > shut down the connection. I am starting a new thread about that. The > problem is larger than it looks, and exists for a long time. I am still wondering if we could put more safeguards in this area though... -- Michael
Commits
-
Fix handling of pg_class.relispartition at swap phase in REINDEX CONCURRENTLY
- eae1ba65fab4 12.1 landed
- d80be6f2f6c9 13.0 landed
-
Handle interrupts within a transaction context in REINDEX CONCURRENTLY
- 7f84b0ef0bfb 12.1 landed
- 8270a0d9a948 13.0 landed