public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: Tomas Vondra <[email protected]>
To: Amit Kapila <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: sequences vs. synchronous replication
Date: Wed, 22 Dec 2021 13:56:23 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CAA4eK1KN-Pqe1y5w0uXU2Ttn8DK4WfqgwAbCRbcDt4yzQ88wRA@mail.gmail.com>
	<[email protected]>



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
>> <[email protected]> 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





view thread (78+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: sequences vs. synchronous replication
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox