pgsql: Fix deadlock hazard in CREATE INDEX CONCURRENTLY

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix deadlock hazard in CREATE INDEX CONCURRENTLY
Date: 2018-01-03 02:20:14
Message-ID: E1eWYf8-0001Na-53@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix deadlock hazard in CREATE INDEX CONCURRENTLY

Multiple sessions doing CREATE INDEX CONCURRENTLY simultaneously are
supposed to be able to work in parallel, as evidenced by fixes in commit
c3d09b3bd23f specifically to support this case. In reality, one of the
sessions would be aborted by a misterious "deadlock detected" error.

Jeff Janes diagnosed that this is because of leftover snapshots used for
system catalog scans -- this was broken by 8aa3e47510b9 keeping track of
(registering) the catalog snapshot. To fix the deadlocks, it's enough
to de-register that snapshot prior to waiting.

Backpatch to 9.4, which introduced MVCC catalog scans.

Include an isolationtester spec that 8 out of 10 times reproduces the
deadlock with the unpatched code for me (Álvaro).

Author: Jeff Janes
Diagnosed-by: Jeff Janes
Reported-by: Jeremy Finzel
Discussion: https://postgr.es/m/CAMa1XUhHjCv8Qkx0WOr1Mpm_R4qxN26EibwCrj0Oor2YBUFUTg%40mail.gmail.com

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/fb7b43903e911fef30c97ee1747ee948f2ba5e28

Modified Files
--------------
src/backend/commands/indexcmds.c | 3 +++
src/test/isolation/expected/multiple-cic.out | 19 +++++++++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/multiple-cic.spec | 40 ++++++++++++++++++++++++++++
4 files changed, 63 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-01-03 02:23:22 pgsql: Ensure proper alignment of tuples in HashMemoryChunkData buffers
Previous Message Tom Lane 2018-01-03 01:38:30 Re: pgsql: Add parallel-aware hash joins.