Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5Zu5-0000Jl-9n for pgsql-bugs@arkaria.postgresql.org; Tue, 02 May 2017 15:39:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d5Zu4-0006Bp-MM for pgsql-bugs@arkaria.postgresql.org; Tue, 02 May 2017 15:39:52 +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 1d5Zu4-0006Bf-5m for pgsql-bugs@postgresql.org; Tue, 02 May 2017 15:39:52 +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 1d5Zu0-0008G1-5N for pgsql-bugs@postgresql.org; Tue, 02 May 2017 15:39:51 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BC28620657; Tue, 2 May 2017 11:39:46 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 02 May 2017 11:39:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=YTyaH+wtqhdAVPL8v2UIbNudseYlG7m4g6zLTmmCX4g=; b=EQQhOMek R/AKpPsRVuL12yjdJ/fP3C/x0AhNM8gQ7ZdSlrozuPs/paF3M+o6eZ4ODihmkA5p xcKrkjSFGW3VxeNWuTK38gbc7NKiAd2m9iEMjpZgCPnEgBDuWL6cnm0wLNI7vnxi 4RiFGegOrJ9GRCSb7xj8XP8kEzcfn7cEr3SbySg/fG1tt3mZbVKXFFg5qY4Yo5UP JPufMdnpgznzSXkIDOI97VltYtR36B42JkQMbySaB7PKYSF9IKfizX6II2Y0aGFc bM0TADOr9zGATF4DZEy71xvgfJB48HwdjRmNXZ6xle1D2HXUP/nxFm1+nUsEvt0U kN/sQuUOS4tV3A== X-ME-Sender: X-Sasl-enc: JZqwkJQRi2HcMcqlqpLePMNYPvOsbadaXmCQagLyFNrn 1493739586 Received: from intern.anarazel.de (unknown [172.58.32.247]) by mail.messagingengine.com (Postfix) with ESMTPA id 5D90F24753; Tue, 2 May 2017 11:39:46 -0400 (EDT) Date: Tue, 2 May 2017 08:39:44 -0700 From: Andres Freund To: Peter Eisentraut Cc: Jason Petersen , pgsql-bugs@postgresql.org Subject: Re: Concurrent ALTER SEQUENCE RESTART Regression Message-ID: <20170502153944.utir7dkdiinpd6uc@alap3.anarazel.de> References: <20170502150744.l6jr32attx2f6575@alap3.anarazel.de> <2adb9428-8cac-6620-3269-9a9a2b8ff6a0@2ndquadrant.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2adb9428-8cac-6620-3269-9a9a2b8ff6a0@2ndquadrant.com> 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 Hi, On 2017-05-02 11:19:08 -0400, Peter Eisentraut wrote: > On 5/2/17 11:07, Andres Freund wrote: > > On 2017-05-02 10:53:19 -0400, Peter Eisentraut wrote: > >> This message comes from the pg_sequence catalog update. But in the case > >> of the RESTART clause, you don't need to update the catalog, because it > >> just needs to write to the sequence's relation. So I have tweaked the > >> code a little to omit the catalog update if it's not needed. Your test > >> case works without errors now. > > > > Wait, how does this *actually* solve anything, but scratch at the > > surface? You just add a MAXVALUE and it starts failing (and not being > > adhered to) again? > > The just committed patch somewhat disentangles the transactional from > the nontransactional parts of ALTER SEQUENCE. > > RESTART is a nontransactional action. Now you get the same concurrency > behavior for RESTART as you would for setval and nextval. This was not > the case prior to the fix. Well, except if specified together with other options. > Other clauses such as MAXVALUE are transactional actions. Yes, and that's a complete mess. Because RESTART relies on the current catalog state in the restarting transaction, but affect other transactions immediately, you can all kind of weird things. S1: CREATE SEQUENCE foo START WITH 100 MINVALUE 10 MAXVALUE 1000; S1: SELECT nextval('foo'); ┌─────────┐ │ nextval │ ├─────────┤ │ 100 │ └─────────┘ S1: BEGIN; S1: ALTER SEQUENCE foo RESTART START WITH 1 MINVALUE 1 MAXVALUE 1000; S2: SELECT nextval('foo'); ┌─────────┐ │ nextval │ ├─────────┤ │ 1 │ └─────────┘ (1 row) -- uh, so we get a value that's below minvalue. Borked transactionality S1: ROLLBACK; S1: SELECT nextval('foo'); ┌─────────┐ │ nextval │ ├─────────┤ │ 2 │ └─────────┘ -- uh, so even worse. We have transactional behaviour (minvalue change), that's not even transactional. And we'll continue to return values that aren't legal to the sequence's definition. In other words, you made alter sequence transactional, except randomly not. I'm increasingly thinking that this change hasn't gotten even close enough scrutiny and should just be reverted. > You get the same concurrency behavior as for most DDL in PostgreSQL. I don't see any evidence of that. > You could > argue that the RowExclusiveLock on pg_sequence in not enough and should > be perhaps ShareRowExclusiveLock to avoid "tuple concurrently updated" > messages. But just over in 521fd4795e3ec3d0b263b62e5eb58e1557be9c86 it > was argued that that sort of thing was undesirable. No, we'd need proper locking on the sequence object, not on pg_sequence. Alter table, and a lot of other commands, primarily rely on proper locking of the underlying object, not on heavyweight locks of pg_class. - Andres -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs