From: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> |
---|---|
To: | bharath(dot)rupireddyforpostgres(at)gmail(dot)com |
Cc: | laurenz(dot)albe(at)cybertec(dot)at, pgsql-hackers(at)lists(dot)postgresql(dot)org, satyanarlapuram(at)gmail(dot)com |
Subject: | Re: An attempt to avoid locally-committed-but-not-replicated-to-standby-transactions in synchronous replication |
Date: | 2022-08-09 07:12:36 |
Message-ID: | 20220809.161236.1486509314201074910.horikyota.ntt@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
At Mon, 8 Aug 2022 19:13:25 +0530, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote in
> On Fri, Aug 5, 2022 at 8:19 AM Kyotaro Horiguchi
> <horikyota(dot)ntt(at)gmail(dot)com> wrote:
> >
> > At Tue, 26 Apr 2022 08:26:59 +0200, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 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 */
<retry?>
}
}
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Smith | 2022-08-09 07:14:54 | Re: Data is copied twice when specifying both child and parent table in publication |
Previous Message | Andres Freund | 2022-08-09 07:10:55 | Re: [RFC] building postgres with meson |