Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkkFU-00042E-KL for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Aug 2017 05:00:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dkkFU-0002HQ-5F for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Aug 2017 05:00:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dkkFS-0002BU-RT for pgsql-bugs@postgresql.org; Thu, 24 Aug 2017 05:00:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dkkFQ-00031o-BJ for pgsql-bugs@postgresql.org; Thu, 24 Aug 2017 05:00:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v7O501BC014187; Thu, 24 Aug 2017 01:00:01 -0400 From: Tom Lane To: Michael Paquier cc: mba.ogolny@gmail.com, PostgreSQL mailing lists Subject: Re: BUG #14768: CREATE INDEX CONCURRENTLY IF NOT EXISTS cancels autovacuum even if the index already exists. In-reply-to: References: <20170802103952.8425.5477@wrigleys.postgresql.org> Comments: In-reply-to Michael Paquier message dated "Thu, 24 Aug 2017 13:35:01 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14185.1503550801.1@sss.pgh.pa.us> Date: Thu, 24 Aug 2017 01:00:01 -0400 Message-ID: <14186.1503550801@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier writes: > On Wed, Aug 2, 2017 at 12:39 PM, wrote: >> I am perfectly aware of the fact that CREATE INDEX CONCURRENTLY on a table >> cancels a running autovacuum process on that table. >> But CREATE INDEX CONCURRENTLY IF NOT EXISTS should take >> ShareUpdateExclusiveLock only after checking that the index doesn't exist. > Logically the checks in index_create could happen in DefineIndex() as > there is no if_not_exists logic for toast indexes. But do we want to > skip all the sanity checks done before that, particularly for > exclusion constraints with concurrent creation? I'm afraid this complaint is just wishful/sloppy thinking. It's useless to perform an "index doesn't exist" check without holding a lock that's sufficient to prevent such an index from being created by a concurrent transaction. There is no lock level less than SHARE UPDATE EXCLUSIVE that would prevent that; and even if there was, taking that level to make the check and then upgrading to SHARE UPDATE EXCLUSIVE would constitute a deadlock risk in itself. Perhaps the OP's problem --- which he failed to state exactly, but I suppose can be written as "I wish a failed CREATE INDEX CONCURRENTLY didn't kill a concurrent autovacuum before failing" --- could be resolved by subdividing SHARE UPDATE EXCLUSIVE into more than one lock level. But that's not exactly a trivial change. And it's not very clear why this is such a big problem that we need to be making a delicate redesign of the locking logic to avoid it. Autovacuum cancels are pretty routine, while I'm having a hard time understanding why index builds would happen so often that they'd lock out autovacuum for problematic amounts of time. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs