From: | Jeff Janes <jeff(dot)janes(at)gmail(dot)com> |
---|---|
To: | Jeremy Finzel <finzelj(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Deadlock between concurrent index builds on different tables |
Date: | 2017-12-23 16:59:38 |
Message-ID: | CAMkU=1xxrepB+oN22Zd15T_Pnt2VAqYptU5U+CqqDfWMn-D+7Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Dec 22, 2017 at 1:53 PM, Jeremy Finzel <finzelj(at)gmail(dot)com> wrote:
> I am attempting to build several indexes in parallel, guaranteeing that I
> never build one on the same table twice. I understand I can't build two on
> the same table at once or I will get a deadlock. However, I am also
> getting a deadlock when doing several in parallel on different tables.
>
> Here is an example of the error I am getting:
>
> 2017-12-22 15:48:07.669 CST,"CREATE INDEX",2017-12-22 15:48:02
> CST,8/32,0,ERROR,40P01,"deadlock detected","Process 4470 waits for
> ShareLock on virtual transaction 4/262; blocked by process 4466.
> Process 4466 waits for ShareLock on virtual transaction 8/32; blocked by
> process 4470.
> Process 4470: CREATE INDEX CONCURRENTLY index_foo_on_created_at ON foo
> USING btree (created_at);
> Process 4466: CREATE INDEX CONCURRENTLY index_bar_on_id ON bar USING btree
> (id);","See server log for query details.",,,,"CREATE INDEX CONCURRENTLY
> index_foo_on_created_at ON foo USING btree (created_at);",,,""
>
> Here is my process:
>
> - Kick off one index build and background 1 second apart, using a
> queue table to determine what indexes to build and what is finished
> - When I determine if a index can be built, I first check if there is
> another already in build on target table before starting another
> - After the index is built in each workflow, I mark it as built in a
> queue table
>
> I assume that one of the indexes (the earlier transaction) is building and
> taking so long that several finished indexes end up waiting, and there is
> perhaps a limit to that?
>
Each index build needs to wait for all other transactions (Including the
ones used by the other index build) to finish. So I don't think a deadlock
here is unexpected.
Cheers,
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | Peter J. Holzer | 2017-12-23 17:09:00 | Re: Array of foreign key |
Previous Message | Martin Marques | 2017-12-23 11:58:42 | Re: Stand by server (9.6.6) with corrupt file |