Re: Switching XLog source from archive to streaming when primary available

From: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, Ian Lawrence Barwick <barwick(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Cary Huang <cary(dot)huang(at)highgo(dot)ca>, SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Switching XLog source from archive to streaming when primary available
Date: 2026-08-24 11:05:16
Message-ID: CAE9k0Pn9P-JAPcR1pV7xF307P=h-AiMwcL=bbQup4APOzDGpMA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Jan 8, 2025 at 5:17 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Thu, Jan 02, 2025 at 11:12:37PM +0500, Andrey M. Borodin wrote:
> > In my observation restore from archive is many orders of magnitude
> > faster than streaming replication. Advanced archive tools employ
> > compression (x6 to speed), download parallelism (x4), are not
> > constrained be primary's network limits (x3) and disk limits, do not
> > depend on complicated FEBE protocol, etc.
>
> This is a fair argument in terms of flexibility of what can be
> achieved on a file-basis, yes, because you are not bottlenecked by
> the existing replication protocol and can request them ahead of time
> if necessary and can decide what you want within a single
> restore_command or archive_command (or module for the latter).
>
> It may be relevant to think in terms of what could be done at protocol
> level to retrieve batches of WAL segments so as the backend has a
> better control on how each segment is handled in a batch, or provide
> better in-core tools to achieve that with the existing two command
> GUCs for restore and archiving? Nathan has also proposed a couple of
> months ago restore modules, because relying on commands can be very
> fancy in terms of error handling. And we already have the archive
> module part.

Reviving this thread - the discussion so far has mostly centered on
whether streaming or archive recovery is faster, and understandably
stalled there since it depends heavily on the environment (storage
type, network, archive tooling). I'd like to set that question aside
and make the case that this patch solves a correctness/availability
problem independent of performance.

The core issue: if a standby remains in archive recovery for an
extended period, its corresponding physical replication slot on the
primary stops advancing - the slot's restart_lsn only moves forward
via streaming feedback, which isn't happening while the standby is
reading from the archive. If the primary is generating WAL at a
meaningful rate during this window, the primary has to retain all of
it for that stalled slot, which can exhaust the primary's data disk
and take it down entirely.

This gets worse with the slot sync feature (PG17). When
synchronized_standby_slots is configured, the primary holds back
logical decoding until every listed physical standby slot has
confirmed receipt of that WAL. The logical slots are tightly coupled
to the physical slot representing the failover-candidate standby. So
if that physical slot stalls because the standby is stuck in archive
mode, logical replication stalls too, not just physical.

In short: the disk-exhaustion risk on the primary, and the
logical-replication stall under slot sync, both stem from the standby
staying in archive mode longer than necessary regardless of whether
streaming would technically be faster in a given environment. I would
suggest we evaluate this patch primarily against that concern, and
treat the performance angle as a secondary benefit rather than the
main justification.

I will rebase the patch (last posted as v24) and follow up with an
updated version if there's interest in continuing this.

--
With Regards,
Ashutosh Sharma.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message ZizhuanLiu X-MAN 2026-08-24 11:19:33 Re: Avoid unnecessary StringInfo allocation in tablesync COPY buffer
Previous Message Ashutosh Bapat 2026-08-24 10:59:54 Re: doc: Reformat SELECT queries using GRAPH_TABLE