| From: | Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Report standby replay progress during archive recovery |
| Date: | 2026-12-01 13:30:55 |
| Message-ID: | CAN55FZ0L2_rRB250RxDb6mKiZaNdH6RJrK2PM_GwGcJvqQSsMQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
In another thread [1], I asked whether a standby could report its
progress while replaying WAL from the archive, without switching back
to streaming. Here is my attempt at implementing that idea.
Consider a standby that normally streams but has a restore_command as
a fallback, as in the setup described [2]. A network outage breaks the
stream and the standby starts reading from the archive. When the
primary is reachable again, the restore tool may already have the next
few segments on disk. Even a link too slow to catch up by streaming
may be enough to send replay reports. The standby can keep using the
archive without forcing the primary to retain WAL it has already
replayed.
This also matters for a logical subscriber using a failover slot. Say
the standby last streamed WAL through 0/3000000 but has since replayed
archived WAL through 0/5000000. If its physical slot is in
synchronized_standby_slots, the primary can still be holding back
changes after 0/3000000 because it hasn't heard from the standby. With
this patch, the physical slot's restart_lsn can advance to 0/5000000.
===
Here is how the feature works:
After a streaming attempt fails, startup requests a feedback-only
walreceiver once it has applied a record from the archive or pg_wal.
This requires both primary_conninfo and primary_slot_name. The
walreceiver connects to its upstream and issues:
`START_FEEDBACK SLOT slot_name TIMELINE tli`
The slot must already have reserved WAL. The walsender advances the
slot only if the reported replay position is on the requested timeline
and is no further than its own flush position (its replay position on
a cascading standby). When startup runs out of archived and local WAL,
it stops the feedback receiver and starts streaming on a fresh
connection.
The feedback connection carries no WAL and cannot acknowledge
synchronous commits. It doesn't send hot_standby_feedback either,
though I think that could be useful as a follow-up.
If the upstream is unreachable, replay continues. Startup can retry as
replay crosses WAL segment boundaries, with
wal_retrieve_retry_interval limiting those attempts. If the feedback
connection is lost, the standby does not retry it while waiting for
replay to resume or for an apply delay to end, even if the primary is
reachable again.
===
Some questions:
- I added START_FEEDBACK command so the standby can report replay for
a named physical slot without asking the upstream to send WAL. Does
that make sense?
- Should the standby also report progress during initial archive
recovery? I limited this to failed streaming attempts so that initial
recovery works as it does today. But if a standby starts with an
archive backlog and keeps finding more WAL there, it may never try
streaming and never report its progress.
===
0001-0003 are refactoring commits.
0004 adds the START_FEEDBACK command.
0005 advances the slot.
0006 adds feedback mode to the walreceiver.
0007 starts feedback mode after a streaming failure.
I used an LLM to generate the first draft of these patches, which I
then reviewed and edited myself.
Any feedback would be appreciated.
[1] https://postgr.es/m/CAN55FZ0un_7O9qAwZcHPYDMfAp6zQzazR1qjPuww_qLz=bJhcQ@mail.gmail.com
[2] https://postgr.es/m/CA+VUV5r0XoJdXpM_NFcxw5_YXmcHoAWb909Fu9ApUsH16Sf6_w@mail.gmail.com
--
Regards,
Nazir Bilal Yavuz
Microsoft
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Share-the-walreceiver-startup-timeout-check.patch | text/x-patch | 2.9 KB |
| v1-0002-Share-the-code-that-sends-CopyBothResponse.patch | text/x-patch | 2.4 KB |
| v1-0003-Pass-the-replication-mode-to-WalSndLoop.patch | text/x-patch | 5.1 KB |
| v1-0004-Add-START_FEEDBACK-for-named-physical-replication.patch | text/x-patch | 30.3 KB |
| v1-0005-Advance-physical-slots-to-the-reported-replay-pos.patch | text/x-patch | 15.4 KB |
| v1-0006-Let-the-walreceiver-report-replay-without-receivi.patch | text/x-patch | 30.1 KB |
| v1-0007-Report-archive-replay-after-a-streaming-failure.patch | text/x-patch | 22.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nazir Bilal Yavuz | 2026-12-01 13:50:42 | Re: Switching XLog source from archive to streaming when primary available |
| Previous Message | Zhijie Hou | 2026-12-01 12:47:52 | Re: Fix race between copying and dropping a replication slot |