Reporting WAL replay progress during pre-consistency standby reovery

Поиск
Список
Период
Сортировка
Искать

Reporting WAL replay progress during pre-consistency standby reovery

От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Hi,

Periodic replay progress reporting could be useful when a new standby
remains unavailable for a long time before reaching consistency. SQL
monitoring is not yet available during this period, and it can be
difficult to determine from the standby logs whether WAL replay is
advancing.

PostgreSQL already periodically reports:

    redo in progress, elapsed time: ..., current LSN: ...

during non-standby recovery. This is intentionally suppressed in
standby mode because a standby can remain in recovery indefinitely,
which could result in unbounded logging.

Would it make sense to emit the existing message only while a standby
has not yet reached consistency, and disable the progress timer as
soon as consistency is reached?

This would help particularly while replaying WAL from pg_wal, for
which there is no per-segment LOG message. During archive recovery,
"restored log file ..." indicates retrieval rather than the current
replay position. Once streaming starts, the primary may expose
replay_lsn through pg_stat_replication, but that does not cover the
earlier local/archive replay period.

The proposal would reuse log_startup_progress_interval and report only
the elapsed time and current replay LSN and it would preserve the
current no-periodic-reporting behavior after consistency.

Does this seem like a useful observability improvement, or is there an
existing way to obtain equivalent replay progress during this period?

If this seems useful, I would be happy to prepare and share a patch.

Best Regards,
Nitin Jadhav
Microsoft


Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Вложения:
Hi,

Attached is a v1 patch implementing the proposed behavior. The patch
enables the existing redo progress reporting while a standby has not
yet reached consistency and disables the progress timer as soon as
consistency is reached. It reuses log_startup_progress_interval and
does not introduce a new GUC or log message.

Please review and share your feedback.

Best Regards,
Nitin Jadhav
Microsoft

Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Pierre Forstmann <pierre.forstmann@gmail.com>
Дата:
The following review has been posted through the commitfest application:
make installcheck-world:  tested, passed
Implements feature:       tested, passed
Spec compliant:           not tested
Documentation:            tested, passed

Hello,

This patch looks good to me.

I have made 2 tests with a standby using log_startup_progress_interval = 1 

With little load on primary I get in standby log:

2026-10-24 15:20:28.178 CEST [59310] LOG:  entering standby mode
2026-10-24 15:20:28.180 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/27537
2026-10-24 15:20:28.181 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/24891
2026-10-24 15:20:28.182 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/4
2026-10-24 15:20:28.183 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/28385
2026-10-24 15:20:28.184 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/16388
2026-10-24 15:20:28.186 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/30501
2026-10-24 15:20:28.186 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/25301
2026-10-24 15:20:28.187 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/29668
2026-10-24 15:20:28.188 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/26081
2026-10-24 15:20:28.189 CEST [59310] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.01 s, current path: base/30560
2026-10-24 15:20:28.190 CEST [59310] LOG:  redo starts at 0/4D000028
cp: impossible d'évaluer '/var/lib/pgsql/sarchive/00000001000000000000004E': Aucun fichier ou dossier de ce nom
2026-10-24 15:20:28.192 CEST [59310] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4D000050
2026-10-24 15:20:28.192 CEST [59310] LOG:  consistent recovery state reached at 0/4E000000
2026-10-24 15:20:28.192 CEST [59304] LOG:  database system is ready to accept read-only connections

If I stop standby, run a large insert on primary and restart standby I get lots of messages in standby log:

2026-10-24 15:28:21.609 CEST [60252] LOG:  entering standby mode
2026-10-24 15:28:21.612 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/18903
2026-10-24 15:28:21.613 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/22741
2026-10-24 15:28:21.614 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/23973
2026-10-24 15:28:21.615 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/25963
2026-10-24 15:28:21.616 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/25796
2026-10-24 15:28:21.618 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/30501
2026-10-24 15:28:21.618 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/21447
2026-10-24 15:28:21.619 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/30579
2026-10-24 15:28:21.621 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.00 s, current path: base/29311
2026-10-24 15:28:21.621 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.01 s, current path: base/25762
2026-10-24 15:28:21.622 CEST [60252] LOG:  resetting unlogged relations (cleanup), elapsed time: 0.01 s, current path: base/30820
2026-10-24 15:28:21.623 CEST [60252] LOG:  redo starts at 0/4E01FFE8
2026-10-24 15:28:21.624 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E026EA0
2026-10-24 15:28:21.625 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E02D3A8
2026-10-24 15:28:21.626 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E033B30
2026-10-24 15:28:21.627 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E03A510
2026-10-24 15:28:21.628 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E040FD8
2026-10-24 15:28:21.629 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E047720
2026-10-24 15:28:21.630 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E04DEA8
2026-10-24 15:28:21.631 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E054908
2026-10-24 15:28:21.632 CEST [60252] LOG:  redo in progress, elapsed time: 0.00 s, current LSN: 0/4E05B410
2026-10-24 15:28:21.633 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E061ED8
2026-10-24 15:28:21.634 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E068A38
2026-10-24 15:28:21.635 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E06F740
2026-10-24 15:28:21.636 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E076320
2026-10-24 15:28:21.637 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E07CDA8
2026-10-24 15:28:21.638 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E0838F0
2026-10-24 15:28:21.639 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E08A450
2026-10-24 15:28:21.640 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E090F58
2026-10-24 15:28:21.641 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E097960
2026-10-24 15:28:21.642 CEST [60252] LOG:  redo in progress, elapsed time: 0.01 s, current LSN: 0/4E09E480
2026-10-24 15:28:21.643 CEST [60252] LOG:  redo in progress, elapsed time: 0.02 s, current LSN: 0/4E0A4FC8
...
...
...
2026-10-24 15:28:21.858 CEST [60252] LOG:  redo in progress, elapsed time: 0.23 s, current LSN: 0/4E6496E0
2026-10-24 15:28:21.858 CEST [60252] LOG:  consistent recovery state reached at 0/4E650718
2026-10-24 15:28:21.858 CEST [60246] LOG:  database system is ready to accept read-only connections

I have checked updated documentation. 

I don't think there is a need to check SQL compliance.

Regards,
PF.

The new status of this patch is: Ready for Committer

Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Oct 8, 2026 at 7:36 PM Nitin Jadhav
 wrote:
> Does this seem like a useful observability improvement, or is there an
> existing way to obtain equivalent replay progress during this period?

What about the startup process title shown by ps? During recovery,
it shows which WAL file is being replayed, even before consistency is
reached. This provides file-level progress, though not the exact replay LSN.

Regards,

-- 
Fujii Masao


Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Hi Fujii-san,

> What about the startup process title shown by ps? During recovery,
> it shows which WAL file is being replayed, even before consistency is
> reached. This provides file-level progress, though not the exact replay LSN.

Thanks for pointing that out.  Yes, the startup process title provides
a useful live indication of the WAL segment currently being replayed.
It should be possible to estimate a coarse replay rate by polling the
process title externally and recording when the WAL filename changes.
However, it does not show progress within a WAL segment and does not
leave a historical record unless such polling is already in place.

Periodic messages containing the replay LSN and a timestamp would make
it possible to calculate the replay rate between samples and perform
after-the-fact analysis using the server logs. This also seems
consistent with the motivation for the existing crash recovery
progress reporting. The original discussion [1] acknowledged that WAL
replay could be identified using ps, but noted that this was less
convenient and worked only while recovery was being observed, rather
than when examining logs afterward. The proposed patch extends that
existing reporting only during the bounded pre-consistency period and
stops it once consistency is reached.

Does that distinction make sense, or do you think the process-title
information is sufficient for this case?

[1] https://postgr.es/m/CA+TgmoaHQrgDFOBwgY16XCoMtXxsrVGFB2jNCvb7-ubuEe1MGg@mail.gmail.com

Best Regards,
Nitin Jadhav
Microsoft


Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
surya poondla <suryapoondla4@gmail.com>
Дата:
Hi Nitin,

I've been looking at this patch and had some thoughts.

Regarding Fujii's point about the process title, it's useful while someone is watching, but it only shows the segment, has to be polled,
and leaves nothing behind afterwards. Before consistency the standby
can't be queried, so the server log is the only lasting record. One more case where this matters, which is after
pg_rewind where backup_label points to the last common checkpoint before the divergence, and minRecoveryPoint is set to the source's insert LSN
at the end of the rewind. Everything in between is replayed before consistency, mostly from local pg_wal, so pg_stat_replication doesn't
cover it either. The patch stops reporting at consistency, so the log-volume reason for suppressing these messages on a standby doesn't
apply.

v1 applies cleanly to current master and builds without warnings.

I think this is worth having and have a few comments:

1. In EnableStandbyMode():

      if (!InRedo || reachedConsistency)
      disable_startup_progress_timeout();

As far as I can see, the only caller that runs during redo is the crash-to-archive recovery switch in ReadRecord(). That code then sets
minRecoveryPoint to xlogreader->EndRecPtr and calls CheckRecoveryConsistency(). backupEndRequired can't be set on that
path (otherwise we'd have entered archive recovery directly), so consistency is reached immediately, and the new
disable_startup_progress_timeout() in CheckRecoveryConsistency() turns
the timer off anyway. Unless I'm missing a path, this code could be dropped, keeping the original unconditional disable.

2. disable_startup_progress_timeout() returns early when log_startup_progress_interval is 0:

      /* Feature is disabled. */
      if (log_startup_progress_interval == 0)
      return;

The setting is PGC_SIGHUP and the startup process rereads it during replay. I tested this on a standby that took about 20s to reach
consistency, with log_startup_progress_interval = 1s, reloading it to 0 a few seconds into replay. After "consistent recovery state reached"
the timer kept firing every second until shutdown (I counted the fires with a temporary counter in the handler), because the disable call in
CheckRecoveryConsistency() does nothing. On master the redo timer is
only enabled outside standby mode, where recovery normally ends soon. With this patch the timer can stay enabled on a normal long-running
standby. Removing the early return fixes it in my test (assert-enabled build). Every caller runs after StartupXLOG() has registered
STARTUP_PROGRESS_TIMEOUT, so disable_timeout() is safe there.

Relatedly, after the reload to 0 the "redo in progress" messages also kept appearing until consistency, since
has_startup_progress_timeout_expired() doesn't check the setting.
Crash recovery uses the same code, so that may be out of scope here.

The documentation change looks fine.

Regards,
Surya Poondla

Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Вложения:
> v1 applies cleanly to current master and builds without warnings.
>
> I think this is worth having and have a few comments:

Thanks for supporting the proposal, reviewing the patch, and catching
these issues. I appreciate the detailed analysis and testing.

I have attached v2 with both changes. I restored the unconditional
disable_startup_progress_timeout() call in EnableStandbyMode() and
removed the log_startup_progress_interval == 0 check from
disable_startup_progress_timeout().

I also tested reloading the interval from one second to zero during
pre-consistency replay and confirmed that the timer stops firing after
consistency.

Please review the v2 patch and let me know if you have any other comments.

Best Regards,
Nitin Jadhav
Microsoft

Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Kirill Reshke <reshkekirill@gmail.com>
Дата:
On Mon, 9 Nov 2026 at 10:11, Nitin Jadhav  wrote:
>
> > v1 applies cleanly to current master and builds without warnings.
> >
> > I think this is worth having and have a few comments:
>
> Thanks for supporting the proposal, reviewing the patch, and catching
> these issues. I appreciate the detailed analysis and testing.
>
> I have attached v2 with both changes. I restored the unconditional
> disable_startup_progress_timeout() call in EnableStandbyMode() and
> removed the log_startup_progress_interval == 0 check from
> disable_startup_progress_timeout().
>
> I also tested reloading the interval from one second to zero during
> pre-consistency replay and confirmed that the timer stops firing after
> consistency.
>
> Please review the v2 patch and let me know if you have any other comments.
>
> Best Regards,
> Nitin Jadhav
> Microsoft


Hi!
During recovery, if you try to connect to the database via psql, you
will get an error message: "the database system is not yet accepting
connection"/"Consistent recovery state has not been yet reached." etc.
What if we report the current replay LSN here?


-- 
Best regards,
Kirill Reshke


Re: Reporting WAL replay progress during pre-consistency standby reovery

От:
Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Дата:
Hi Kiril,

> During recovery, if you try to connect to the database via psql, you
> will get an error message: "the database system is not yet accepting
> connection"/"Consistent recovery state has not been yet reached." etc.
> What if we report the current replay LSN here?

Thanks for the suggestion. Since crash recovery already reports replay
progress through the server log, I think using the same mechanism for
standby recovery before consistency is preferable than introducing a
different reporting method.

Also, this connection error is returned before authentication, so
adding the replay LSN would expose recovery information to
unauthenticated clients and may need separate consideration.

For this patch, I would prefer to keep the existing server-log
approach, while the connection-error approach can be explored
separately.

Best Regards,
Nitin Jadhav
Microsoft


FAQ