Re: synchronous_commit = apply - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: synchronous_commit = apply
Date
Msg-id CAHGQGwFW-TDCC7rPjnWNM5ngp2dmMZ8LL_jp2bSFRgCUnp7aXQ@mail.gmail.com
Whole thread Raw
In response to synchronous_commit = apply  (Thomas Munro <thomas.munro@enterprisedb.com>)
List pgsql-hackers
On Wed, Sep 2, 2015 at 10:25 AM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> Hi
>
> Do you think it's reasonable to want to COMMIT a particular transaction on a
> master node, and then immediately run a read-only query on a hot standby
> node that is guaranteed to see that transaction?
>
> A friend of mine who works with a different RDBMS technology that can do
> that asked me how to achieve this with Postgres, and I suggested waiting for
> the standby's pg_last_xlog_replay_location() to be >= the master's
> pg_current_xlog_location() after COMMIT, which might involve some looping
> and sleeping.
>
> As a quick weekend learning exercise/hack I recently went looking into how
> we could support $SUBJECT.  I discovered we already report the apply
> progress back to the master, and the synchronous waiting facility seemed to
> be all ready to support this.  In fact it seemed a little too easy so
> something tells me it must be wrong!  But anyway, please see the attached
> toy POC patch which does that.
>
> The next problem is that the master can be waiting quite a long time for a
> reply from the remote walreceiver containing the desired apply LSN: in the
> best case it learns of apply progress from replies to subsequent unrelated
> records (which might be very soon on a busy system but still involves
> waiting for the next transaction's WAL flush), and in the worst case it
> needs to wait for wal_receiver_status_interval (10 seconds by default),
> which makes for a long COMMIT delay.  I was thinking that the solution to
> that may be to teach StartupLOG to signal the walreceiver after it updates
> XLogCtl->lastReplayedEndRecPtr, which should cause walrcv_receive to be
> interrupted and return early, and then walreceiver could send a reply if it
> sees that lastReplayedEndRecPtr has moved.  Maybe that would generate an
> unacceptably high frequency of signals

One idea is to change the standby so that it manages the locations
that the backends in "apply" mode are waiting for in the master,
and to make the startup process wake the walreceiver up whenever
the replay location reaches either of those locations. In this idea,
walreceiver sends back the "apply" location to the master only when
needed.

Regards,

-- 
Fujii Masao



pgsql-hackers by date:

Previous
From: "张广舟(明虚)"
Date:
Subject: about fsync in CLOG buffer write
Next
From: Andres Freund
Date:
Subject: Re: about fsync in CLOG buffer write