Re: [ADMIN] Simultaneous index creates on different schemas cause deadlock? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [ADMIN] Simultaneous index creates on different schemas cause deadlock?
Date
Msg-id 10635.1366910251@sss.pgh.pa.us
Whole thread Raw
Responses Re: [ADMIN] Simultaneous index creates on different schemas cause deadlock?  (Andres Freund <andres@2ndquadrant.com>)
Re: [ADMIN] Simultaneous index creates on different schemas cause deadlock?  (Paul Hinze <paul.t.hinze@gmail.com>)
List pgsql-hackers
Paul Hinze <paul.t.hinze@gmail.com> writes:
> [ multiple CREATE INDEX CONCURRENTLY commands will deadlock with each other ]

Hm.  I guess the reason nobody noticed this before now is that generally
the idea with CREATE INDEX CONCURRENTLY is to minimize the impact on
system load, hence you wouldn't do more than one at a time.  Still, it's
surely a POLA violation that you *can't* do more than one at a time.

The cause is that each one will wait for all older snapshots to be
gone --- and it does that before dropping its own snapshot, so that the
other ones will see it as something to be waited out too.

Since we know that C.I.C. executes in its own transaction, and there
can't be more than one on the same table due to locking, it seems to me
that it'd be safe to drop our own snapshot before waiting for other
xacts to end.  That is, we could just rearrange the last few steps in
DefineIndex(), taking care to save snapshot->xmin before we destroy the
snapshot so that we still have that value to pass to
GetCurrentVirtualXIDs().

Anybody see a flaw in that solution?

            regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: minimizing the target list for foreign data wrappers
Next
From: Andres Freund
Date:
Subject: Re: [ADMIN] Simultaneous index creates on different schemas cause deadlock?