Re: BUG #19897: Recovery fails after "LOG: consistent recovery state reached"

From: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>
To: harukat(at)sraoss(dot)co(dot)jp, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19897: Recovery fails after "LOG: consistent recovery state reached"
Date: 2026-11-13 16:40:03
Message-ID: CAFC+b6qWDa-5OD-=ZNSCVcY6xBEas1Ut4c0irm-+kCeYNypGAg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

Thanks for the report and the analysis. I can reproduce this on master.

On Fri, Nov 13, 2026 at 2:27 PM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

>
> diff --git a/src/backend/access/transam/xlogrecovery.c
> b/src/backend/access/transam/xlogrecovery.c
> index 52ac6d58423..796226efad4 100644
> --- a/src/backend/access/transam/xlogrecovery.c
> +++ b/src/backend/access/transam/xlogrecovery.c
> @@ -2789,6 +2789,20 @@ recoveryStopsAfter(XLogReaderState *record)
> return true;
> }
>
> + /* Check if we should stop as soon as reaching consistency */
> + if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE &&
> reachedConsistency)
> + {
> + ereport(LOG,
> + (errmsg("recovery stopping after reaching
> consistency")));
> +
> + recoveryStopAfter = true;
> + recoveryStopXid = InvalidTransactionId;
> + recoveryStopTime = 0;
> + recoveryStopLSN = InvalidXLogRecPtr;
> + recoveryStopName[0] = '\0';
> + return true;
> + }
> +
> if (rmid != RM_XACT_ID)
> return false;
>
> @@ -2867,20 +2881,6 @@ recoveryStopsAfter(XLogReaderState *record)
> }
> }
>
> - /* Check if we should stop as soon as reaching consistency */
> - if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE &&
> reachedConsistency)
> - {
> - ereport(LOG,
> - (errmsg("recovery stopping after reaching
> consistency")));
> -
> - recoveryStopAfter = true;
> - recoveryStopXid = InvalidTransactionId;
> - recoveryStopTime = 0;
> - recoveryStopLSN = InvalidXLogRecPtr;
> - recoveryStopName[0] = '\0';
> - return true;
> - }
> -
> return false;
> }
>

Your proposed fix of moving the check above the rmgr test does fix the
reported case. But if the record that makes us consistent is a commit
or abort, it now returns before the SetLatestXTime() call, so the "last
completed transaction" time and pg_last_xact_replay_timestamp() would
miss that transaction. The attached 0001 instead goes back to the
pre-4f1b890b137 structure: the rmgr test becomes part of the condition
for the transaction-record block, so the SetLatestXTime still happens and
the immediate check is reached for every record. If this patch makes sense
i will write a TAP test, thoughts?

--
Thanks :)
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

Attachment Content-Type Size
v1-0001-Fix-recovery_target-immediate-when-WAL-ends-at-th.patch application/octet-stream 2.0 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Corey Huinker 2026-11-13 16:07:17 Re: BUG #19842: pg_restore_extended_stats() rejects a faithful pg_dump of ANALYZE-produced range expression statisti