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 1oLJQ7-0008J9-2K for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Aug 2022 07:12:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oLJQ5-0004Od-Ta for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Aug 2022 07:12:53 +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 1oLJQ5-0004Mx-KK for pgsql-hackers@lists.postgresql.org; Tue, 09 Aug 2022 07:12:53 +0000 Received: from mail-vs1-xe33.google.com ([2607:f8b0:4864:20::e33]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oLJQ3-00013B-8I for pgsql-hackers@lists.postgresql.org; Tue, 09 Aug 2022 07:12:52 +0000 Received: by mail-vs1-xe33.google.com with SMTP id m67so11005691vsc.12 for ; Tue, 09 Aug 2022 00:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Tg1MjATXpaVLdc08I7YHjzwHNQnrtXN5eUecFPcgd3M=; b=hZ3Aux69CM8YB/gqVarYrGHFaGVTMToo6vVe8+mTS5eCORBgzGWNZJnQnFLgd8wE3W IkaEe7M68sLn5UT8qTOWeoSTwcL45xImEOCGcHNIMIUCJapbhLsxUK63zrLNB147NPE4 qR2opmicJKDt0cKmKBFy8QVgSmE8KyPG+hR1UWVPKpPkTASP4n2XD+PiTqMUlXUpyzBd zyrLF6lrqc4m/qL+2oloVyori7l/ziLI8HDt5qlVfbAnWHQU8bRunEYipQJ2J9b4GQ9/ nwCdok8SP5FLxXS0XtbcW6RM+nqH2RhLvwnEmG6LGjfElf4CrdF4mZNFXd9NGmwhTWxh s7ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Tg1MjATXpaVLdc08I7YHjzwHNQnrtXN5eUecFPcgd3M=; b=7adFh9/wKo0eqLAbk7XOQ6PaNSS50uKrDvFSm5oVUgftVt9ucGnIikjr+qBIN+UvCy lIOjKaPK1dX3zI0LgIOs2U+2aeD2AH3LCgXdJilkGn+D7CXQqLOfWv6rVshjpjjZRw3f sSYdk/HrffB8CFjwL4ccRsPBWTUQiJieLKmp/Ps7dsGPeqNdiSw+yEtMcwmn/HmvWvQ7 rF7Yb83P2jsHr77OLLfRMG10fiSJpWWKd67ZnuRWfeive/QTwfnlML7pAVNozODRW7P4 PnRW4Ry8rgvxvydVYYKQ6gtA0gHQAbDHIhkvoPtCGrW8j4SSct92XdZZ0bWBVKAtAnoX vlLw== X-Gm-Message-State: ACgBeo1sKgPnlYo79adBqAdJkqMqotSf4DYpD6uPI9TNVZbQHHX5YYVq Jmt0N58BcFmRcRpqkiwSE25iYn+Lqe8= X-Google-Smtp-Source: AA6agR66gYRrSLscjGycYvm+NRJ5npMVCUeMMJE3iJZ5JKYgYDowPo/T8fhNqHgabFpEfgjnapCgTg== X-Received: by 2002:a17:902:e80e:b0:16f:14ea:897b with SMTP id u14-20020a170902e80e00b0016f14ea897bmr21669958plg.6.1660029159987; Tue, 09 Aug 2022 00:12:39 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016f975be2e7sm7454297plb.139.2022.08.09.00.12.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Aug 2022 00:12:39 -0700 (PDT) Date: Tue, 09 Aug 2022 16:12:36 +0900 (JST) Message-Id: <20220809.161236.1486509314201074910.horikyota.ntt@gmail.com> To: bharath.rupireddyforpostgres@gmail.com Cc: laurenz.albe@cybertec.at, pgsql-hackers@lists.postgresql.org, satyanarlapuram@gmail.com Subject: Re: An attempt to avoid locally-committed-but-not-replicated-to-standby-transactions in synchronous replication From: Kyotaro Horiguchi In-Reply-To: References: <9290b55b6ae2b04e002ca9dadadd1cca09461482.camel@cybertec.at> <20220805.114916.994654810780821553.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Mon, 8 Aug 2022 19:13:25 +0530, Bharath Rupireddy wrote in > On Fri, Aug 5, 2022 at 8:19 AM Kyotaro Horiguchi > wrote: > > > > At Tue, 26 Apr 2022 08:26:59 +0200, Laurenz Albe wrote in > > > While this may mitigate the problem, I don't think it will deal with > > > all the cases which could cause a transaction to end up committed locally, > > > but not on the synchronous standby. I think that only using the full > > > power of two-phase commit can make this bulletproof. > > > > > > Is it worth adding additional complexity that is not a complete solution? > > > > I would agree to this. Likewise 2PC, whatever we do to make it > > perfect, we're left with unresolvable problems at least for now. > > > > Doesn't it meet your requirements if we have a means to know the last > > transaction on the current session is locally committed or aborted? > > > > We are already internally managing last committed LSN. I think we can > > do the same thing about transaction abort and last inserted LSN and we > > can expose them any way. This is way simpler than the (maybe) > > uncompletable attempt to fill up the deep gap. > > There can be more txns that are > locally-committed-but-not-yet-replicated. Even if we have that > information stored somewhere, what do we do with it? Those txns are > committed from the client perspective but not committed from the > server's perspective. > > Can you please explain more about your idea, I may be missing something? (I'm not sure I understand the requirements here..) I understand that it is about query cancellation. In the case of primary crash/termination, client cannot even know whether the commit of the ongoing transaction, if any, has been recorded. Anyway no way other than to somehow confirm that the change by the transaction has been actually made after restart. I believe it is the standard practice of the applications that work on HA clusters. The same is true in the case of query cancellation since commit response doesn't reach the client, too. But even in this case if we had functions/views that tells us the last-committed/last-aborted/last-inserted LSN on a session, we can know whether the last transaction has been committed along with the commit LSN maybe more easily. # In fact, I see those functions rather as a means to know whether a # change by the last transaction on a session is available on some # replica. For example, the below heavily simplified pseudo code might display how the fucntions (if they were functions) work. try { s.execute("INSERT .."); c.commit(); } catch (Exception x) { c.commit(); if (s.execute("SELECT pg_session_last_committed_lsn() = " "pg_session_last_inserted_lsn()")) { /* the transaction has been locally committed */ if (s.execute("SELECT replay_lsn >= pg_session_last_committed_lsn() " "FROM pg_stat_replication where xxxx") /* the commit has been replicated to xxx, LSN is known */ } else { /* the transaction has not been locally committed */ } } regards. -- Kyotaro Horiguchi NTT Open Source Software Center