Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myRiL-0008Kj-Ck for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Dec 2021 04:52:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1myRiJ-0003fF-6e for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Dec 2021 04:52:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myRiI-0003f5-TZ for pgsql-hackers@lists.postgresql.org; Sat, 18 Dec 2021 04:52:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myRiG-0006FR-6b for pgsql-hackers@lists.postgresql.org; Sat, 18 Dec 2021 04:52:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BI4qmpG1452363; Fri, 17 Dec 2021 23:52:48 -0500 From: Tom Lane To: Tomas Vondra cc: PostgreSQL Hackers Subject: Re: sequences vs. synchronous replication In-reply-to: <712cad46-a9c8-1389-aef8-faf0203c9be9@enterprisedb.com> References: <712cad46-a9c8-1389-aef8-faf0203c9be9@enterprisedb.com> Comments: In-reply-to Tomas Vondra message dated "Sat, 18 Dec 2021 02:53:49 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1452361.1639803168.1@sss.pgh.pa.us> Date: Fri, 17 Dec 2021 23:52:48 -0500 Message-ID: <1452362.1639803168@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > The problem is exactly the same as in [1] - the aborted transaction > generated WAL, but RecordTransactionAbort() ignores that and does not > update LogwrtResult.Write, with the reasoning that aborted transactions > do not matter. But sequences violate that, because we only write WAL > once every 32 increments, so the following nextval() gets "committed" > without waiting for the replica (because it did not produce WAL). Ugh. > I'm not sure this is a clear data corruption bug, but it surely walks > and quacks like one. My proposal is to fix this by tracking the lsn of > the last LSN for a sequence increment, and then check that LSN in > RecordTransactionCommit() before calling XLogFlush(). (1) Does that work if the aborted increment was in a different session? I think it is okay but I'm tired enough to not be sure. (2) I'm starting to wonder if we should rethink the sequence logging mechanism altogether. It was cool when designed, but it seems really problematic when you start thinking about replication behaviors. Perhaps if wal_level > minimal, we don't do things the same way? regards, tom lane