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 1mztgc-0002ZI-Ga for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Dec 2021 04:57:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mztg4-0007Hw-Am for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Dec 2021 04:56:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mztg3-0007Hn-W3 for pgsql-hackers@lists.postgresql.org; Wed, 22 Dec 2021 04:56:35 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mztfw-00042s-6r for pgsql-hackers@lists.postgresql.org; Wed, 22 Dec 2021 04:56:34 +0000 Received: from [172.20.10.7] (sp49-98-212-65.msd.spmode.ne.jp [49.98.212.65]) by oss.nttdata.com (Postfix) with ESMTPSA id 0E4906120A; Wed, 22 Dec 2021 13:56:24 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.4 at oss.nttdata.com Message-ID: <6597cf88-a499-e5be-e027-62753b197500@oss.nttdata.com> Date: Wed, 22 Dec 2021 13:56:23 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: sequences vs. synchronous replication Content-Language: en-US To: Tomas Vondra , Amit Kapila Cc: PostgreSQL Hackers References: <712cad46-a9c8-1389-aef8-faf0203c9be9@enterprisedb.com> <4450cd74-1a41-ec03-83ee-fcabc183715d@enterprisedb.com> From: Fujii Masao In-Reply-To: <4450cd74-1a41-ec03-83ee-fcabc183715d@enterprisedb.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021/12/22 10:57, Tomas Vondra wrote: > > > On 12/19/21 04:03, Amit Kapila wrote: >> On Sat, Dec 18, 2021 at 7:24 AM Tomas Vondra >> wrote: >>> >>> while working on logical decoding of sequences, I ran into an issue with >>> nextval() in a transaction that rolls back, described in [1]. But after >>> thinking about it a bit more (and chatting with Petr Jelinek), I think >>> this issue affects physical sync replication too. >>> >>> Imagine you have a primary <-> sync_replica cluster, and you do this: >>> >>>     CREATE SEQUENCE s; >>> >>>     -- shutdown the sync replica >>> >>>     BEGIN; >>>     SELECT nextval('s') FROM generate_series(1,50); >>>     ROLLBACK; >>> >>>     BEGIN; >>>     SELECT nextval('s'); >>>     COMMIT; >>> >>> The natural expectation would be the COMMIT gets stuck, waiting for the >>> sync replica (which is not running), right? But it does not. >>> >> >> How about if we always WAL log the first sequence change in a transaction? >> > > I've been thinking about doing something like this, but I think it would not have any significant advantages compared to using "SEQ_LOG_VALS 0". It would still have the same performance hit for plain nextval() calls, and there's no measurable impact on simple workloads that already write WAL in transactions even with SEQ_LOG_VALS 0. Just idea; if wal_level > minimal, how about making nextval_internal() (1) check whether WAL is replicated to sync standbys, up to the page lsn of the sequence, and (2) forcibly emit a WAL record if not replicated yet? The similar check is performed at the beginning of SyncRepWaitForLSN(), so probably we can reuse that code. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION