Re: Unnecessary delay in streaming replication due to replay lag

From: Asim Praveen <pasim(at)vmware(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, "Hao Wu (Pivotal)" <hawu(at)pivotal(dot)io>
Subject: Re: Unnecessary delay in streaming replication due to replay lag
Date: 2020-08-10 04:31:05
Message-ID: 4052159A-DBB7-4F77-A1B0-BD00D3885FA0@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 09-Aug-2020, at 2:11 PM, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> I have not really looked at the proposed patch, but it would be good
> to have some documentation.
>

Ah, right. The basic idea is to reuse the logic to allow read-only connections to also start WAL streaming. The patch borrows a new GUC “wal_receiver_start_condition” introduced by another patch alluded to upthread. It affects when to start WAL receiver process on a standby. By default, the GUC is set to “replay”, which means no change in current behavior - WAL receiver is started only after replaying all WAL already available in pg_wal. When set to “consistency”, WAL receiver process is started earlier, as soon as consistent state is reached during WAL replay.

The LSN where to start streaming from is determined to be the LSN that points at the beginning of the WAL segment file that was most recently flushed in pg_wal. To find the most recently flushed WAL segment, first blocks of all WAL segment files in pg_wal, starting from the segment that contains currently replayed record, are inspected. The search stops when a first page with no valid header is found.

The benefits of starting WAL receiver early are mentioned upthread but allow me to reiterate: as WAL streaming starts, any commits that are waiting for synchronous replication on the master are unblocked. The benefit of this is apparent in situations where significant replay lag has been built up and the replication is configured to be synchronous.

Asim

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2020-08-10 04:54:23 Re: display offset along with block number in vacuum errors
Previous Message Justin Pryzby 2020-08-10 02:24:43 Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly