Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8Jsg-0004iG-Ee for pgsql-bugs@arkaria.postgresql.org; Wed, 10 May 2017 05:09:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d8Jsg-0007pb-1P for pgsql-bugs@arkaria.postgresql.org; Wed, 10 May 2017 05:09:46 +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 1d8Jse-0007ol-Qz; Wed, 10 May 2017 05:09:44 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d8Jsa-0000Tn-OV; Wed, 10 May 2017 05:09:44 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id DC53720830; Wed, 10 May 2017 01:09:38 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Wed, 10 May 2017 01:09:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=lKk8JmhcEtejF1utdE aBLWsJZCdYoSifLWXR58/bnLU=; b=X/4MHgKeXjLWzz6EcwV2EsdF5u9FUb8DnP j2ICG7Pt7S/qqG2JVt3ip/fHkSqWlvx9umNW9Snmk3fmyhuJVw22DQ4SaH1UEUTh ljQl+St5bJWsfjcylNBw1D3ElcJndrbJLIrF/xXpz2CklpoHN1/kKr4SSbQIhF6Q 709lcZ4MwoRUVkkZLV+aETSWK2mnLlcx53f2IRpgJrbPRFMpK8jyPeh1CpOpet5M yQDU/2cJxX6JysTS69KZDFseBUbwh1MsN6mjerBz7h2u4/k+Loeqxp/2gqxxlXfM 1GIqmPu4JkVIiySHMsK1iEpKuktYqxjogzt7bdKbxyug4Pk5hAUw== X-ME-Sender: X-Sasl-enc: 5TsIgH+ChYPE90uS9G6nsAhg1EfVtFGf5dGfYgPAdb/N 1494392978 Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 2CE437E86A; Wed, 10 May 2017 01:09:38 -0400 (EDT) Subject: Re: Concurrent ALTER SEQUENCE RESTART Regression To: Andres Freund , pgsql-hackers@postgresql.org References: <99a009ea-1797-5b82-f3d3-eb4a5a8eb5dc@2ndquadrant.com> <20170427011258.2tpv55b6leqe2uva@alap3.anarazel.de> <1e5bb916-fd58-3995-851b-6875c6dd73eb@2ndquadrant.com> <20170427055806.uviqrl57lkgcmmmy@alap3.anarazel.de> <20170427062304.gxh3rczhh6vblrwh@alap3.anarazel.de> <20170430080517.GA811193@rfd.leadboat.com> <59aeb834-b113-6769-bfe4-65f2f8c875e3@2ndquadrant.com> <20170507234334.yimkp6aq2o43wtt2@alap3.anarazel.de> Cc: Noah Misch , Jason Petersen , Michael Paquier , PostgreSQL mailing lists From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <4521f870-bb1f-1b29-3b3f-42419696efe7@2ndquadrant.com> Date: Wed, 10 May 2017 01:09:37 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170507234334.yimkp6aq2o43wtt2@alap3.anarazel.de> Content-Type: multipart/mixed; boundary="------------DD308D3FEF781472E205F35F" X-Pg-Spam-Score: -2.6 (--) 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 This is a multi-part message in MIME format. --------------DD308D3FEF781472E205F35F Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 5/7/17 19:43, Andres Freund wrote: > 3. Keep the catalog, make ALTER properly transactional, blocking > concurrent nextval()s. This resolves the issue that nextval() can't > see the changed definition of the sequence. This was the intended choice. I think I have more clarity about the different, overlapping issues: 1. Concurrent ALTER SEQUENCE causes "tuple concurrently updated" error, caused by updates to pg_sequence catalog. This can be fixed by taking a self-exclusive lock somewhere. A typical answer for other catalogs is to use ShareRowExclusiveLock. But in another context it was argued that is undesirable for other reasons, and it's better to stick with RowExclusiveLock and deal with the occasional consequences. But this question is obsoleted by #2. 2. There is some inconsistency or disagreement about what to lock when modifying relation metadata. When you alter a non-relation object, you just have the respective catalog to lock, and you have to make the trade-offs described in #1. When you alter a relation object, you can lock the catalog or the actual relation, or both. I had gone with locking the catalog, but existing practice in tablecmds.c is to lock the relation with the most appropriate lock level, and use RowExclusiveLock for the catalog. We can make sequences do that, too. 3. Sequence WAL writes and catalog updates are not protected by same lock. We can fix that by holding a lock longer. If per #2 we make the lock on the sequence the "main" one, then we just hold that one across the catalog update. 4. Some concerns about in AlterSequence() opening the pg_sequence catalog while holding the sequence buffer lock. Move some things around to fix that. 5. nextval() disregarding uncommitted ALTER SEQUENCE changes. In