Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUFio-0003zH-Ag for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2017 17:42:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUFin-00078g-G3 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2017 17:42:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eUFim-00078W-RM for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2017 17:42:29 +0000 Received: from resqmta-ch2-06v.sys.comcast.net ([2001:558:fe21:29:69:252:207:38]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eUFij-00015K-2U for pgsql-hackers@postgresql.org; Wed, 27 Dec 2017 17:42:28 +0000 Received: from resomta-ch2-14v.sys.comcast.net ([69.252.207.110]) by resqmta-ch2-06v.sys.comcast.net with ESMTP id UFi5eYaYcUMkmUFidex0Rl; Wed, 27 Dec 2017 17:42:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1514396539; bh=lVoExUJGBIc4ILEeVdLXm0ymmOHVGsoABuYpq2biUNA=; h=Received:Received:Received:From:To:Subject:Date:Message-ID: MIME-Version:Content-Type; b=LHiGqpiqr0WA8lz4S1cW/WkXkcdOgLjUfNV6d73gsYAE5uishHmXEbQl5EGBy2f+B SEvg/Q5Kqj3+JTKMDoq+4WYnncjSHSZe2PZQz1LxRmlkuOnCwXMKIohG5n5msCVB+q knKbPCQwCGK98gZ19A0z1pEJKQihXDLtAjNQa4tOAssatcyWFvLKPLwCFZq92bbNGr q0vYIO43bTkZRZbD7iZx4ZsMnJdtbimp/6ss0Vc+PTnnZD0sHoZ45QqaGWxjnnOQvz 8shj9kGe2heR9XnzS7SkYtZQHcZtP3wYoOJnMia55wODuEVcWisHv9f8eMWQR1guud AkCJIzr15nm/Q== Received: from jsievers.comcast.net ([12.30.159.20]) by resomta-ch2-14v.sys.comcast.net with SMTP id UFiNe8lKW9aG0UFiQexpIY; Wed, 27 Dec 2017 17:42:17 +0000 Received: from jsievers.enova.com (localhost [127.0.0.1]) by jsievers.comcast.net (Postfix) with ESMTP id ED56B260104; Wed, 27 Dec 2017 11:42:02 -0600 (CST) From: Jerry Sievers To: Jeff Janes Cc: Alvaro Herrera , pgsql-hackers , Jeremy Finzel Subject: Re: Deadlock in multiple CIC. References: <20171226163103.uzs7oq2fsvo3ugtw@alvherre.pgsql> Date: Wed, 27 Dec 2017 11:42:02 -0600 In-Reply-To: (Jeff Janes's message of "Tue, 26 Dec 2017 09:23:32 -0800") Message-ID: <87mv24ax05.fsf@jsievers.enova.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CMAE-Envelope: MS4wfIPsvVR3DDtOCOEuLqToaQ/rUAbog3h5eQdNhg6zJIS9NBYSnQgF/6EfOlF1n2Xx7FPT2HKPuMsokGt0kUKXv+VW4Pg+ukXYVxPYHcyzT1gvF/WratV1 NjIA1SliPAGEKGowQZE0RgYuRB6SBgO+S7CQ7zCnvmrX4zTq/m4nmwAGk++WnfWHrdsUoYXTPnrZcf2kP2RJjCP34UzqEQmktwm0bGlvluJKegzcQkVfnxNr d1IiiayudkompB60SjY3VyAx+zh7X55Td8o1FLikFW0CkhWootPI3d9as17jhAUh List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeff Janes writes: > On Tue, Dec 26, 2017 at 8:31 AM, Alvaro Herrera < > alvherre@alvh.no-ip.org> wrote: > > Jeff Janes wrote: > > c3d09b3bd23f5f6 fixed it so concurrent CIC would not deadlock > (or at least > > not as reliably as before) by dropping its own snapshot before > waiting for > > all the other ones to go away. > > > > With commit 8aa3e47510b969354ea02a, concurrent CREATE INDEX > CONCURRENTLY on > > different tables in the same database started deadlocking > against each > > other again quite reliably. > > > > I think the solution is simply to drop the catalog snapshot as > well, as in > > the attached. >=20=20=20=20 > Thanks for the analysis -- it sounds reasonable to me.=C2=A0 However, > I'm > wondering why you used the *Conditionally() version instead of > plain > InvalidateCatalogSnapshot(). > > > My thinking was that if there was for some reason another snapshot > hanging around, that dropping the catalog snapshot unconditionally > would be a correctness bug, while doing it conditionally would just > fail to avoid a theoretically avoidable deadlock.=C2=A0 So it seemed > safer. > =C2=A0 > > =C2=A0 I think they must have the same effect in > practice (the assumption being that you can't run CIC in a > transaction > that may have other snapshots) but the theory seems simpler when > calling > the other routine: just do away with the snapshot always, period. > > > That is probably true.=C2=A0 But I never even knew that catalog snapshots > existed until yesterday, so didn't want to make make assumptions > about what else might exist, to avoid introducing new bugs similar to > the one that 8aa3e47510b969354ea02a fixed. > =C2=A0 > >=20=20=20=20 > This is back-patchable to 9.4, first branch which has MVCC > catalog > scans.=C2=A0 It's strange that this has gone undetected for so long. > > > Since the purpose of CIC is to build an index with minimal impact on > other users, I think wanting to use it in concurrent cases might be > rather rare.=C2=A0 In a maintenance window, I wouldn't want to use CIC > because it is slower and I'd rather just hold the stronger lock and > do it fast, and as a hot-fix outside a maintenance window I usually > wouldn't want to hog the CPU with concurrent builds when I could do Hmmm, given that most/all large sites lately are probably running on hw with dozens or perhaps hundreds of CPUs/threads, I can see DBAs not being too concerned about "hogging". > them sequentially instead.=C2=A0 Also, since deadlocks are "expected" > errors rather than "should never happen" errors, and since the docs > don't promise that you can do parallel CIC without deadlocks, many > people would probably shrug it off (which I initially did) rather > than report it as a bug.=C2=A0 I was looking into it as an enhancement > rather than a bug until I discovered that it was already enhanced and Agree such an edge case not a high priority to support for the above reasons but good to assuming no breakage in some other regard :-) > then undone. > > Cheers, > > Jeff > > > > --=20 Jerry Sievers Postgres DBA/Development Consulting e: postgres.consulting@comcast.net p: 312.241.7800