mirror of https://github.com/postgres/postgres
Multiple sessions doing CREATE INDEX CONCURRENTLY simultaneously are supposed to be able to work in parallel, as evidenced by fixes in commitpull/25/headc3d09b3bd2
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 by8aa3e47510
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
parent
438036264a
commit
54eff5311d
@ -0,0 +1,19 @@ |
||||
Parsed test spec with 2 sessions |
||||
|
||||
starting permutation: s2l s1i s2i |
||||
step s2l: SELECT pg_advisory_lock(281457); |
||||
pg_advisory_lock |
||||
|
||||
|
||||
step s1i: |
||||
CREATE INDEX CONCURRENTLY mcic_one_pkey ON mcic_one (id) |
||||
WHERE lck_shr(281457); |
||||
<waiting ...> |
||||
step s2i: |
||||
CREATE INDEX CONCURRENTLY mcic_two_pkey ON mcic_two (id) |
||||
WHERE unlck(); |
||||
|
||||
step s1i: <... completed> |
||||
s1 |
||||
|
||||
|
@ -0,0 +1,40 @@ |
||||
# Test multiple CREATE INDEX CONCURRENTLY working simultaneously |
||||
|
||||
setup |
||||
{ |
||||
CREATE TABLE mcic_one ( |
||||
id int |
||||
); |
||||
CREATE TABLE mcic_two ( |
||||
id int |
||||
); |
||||
CREATE FUNCTION lck_shr(bigint) RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$ |
||||
BEGIN PERFORM pg_advisory_lock_shared($1); RETURN true; END; |
||||
$$; |
||||
CREATE FUNCTION unlck() RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$ |
||||
BEGIN PERFORM pg_advisory_unlock_all(); RETURN true; END; |
||||
$$; |
||||
} |
||||
teardown |
||||
{ |
||||
DROP TABLE mcic_one, mcic_two; |
||||
DROP FUNCTION lck_shr(bigint); |
||||
DROP FUNCTION unlck(); |
||||
} |
||||
|
||||
session "s1" |
||||
step "s1i" { |
||||
CREATE INDEX CONCURRENTLY mcic_one_pkey ON mcic_one (id) |
||||
WHERE lck_shr(281457); |
||||
} |
||||
teardown { SELECT pg_advisory_unlock_all() AS "s1"; } |
||||
|
||||
|
||||
session "s2" |
||||
step "s2l" { SELECT pg_advisory_lock(281457); } |
||||
step "s2i" { |
||||
CREATE INDEX CONCURRENTLY mcic_two_pkey ON mcic_two (id) |
||||
WHERE unlck(); |
||||
} |
||||
|
||||
permutation "s2l" "s1i" "s2i" |
Loading…
Reference in new issue