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

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, harukat(at)sraoss(dot)co(dot)jp
Subject: Re: BUG #19897: Recovery fails after "LOG: consistent recovery state reached"
Date: 2026-11-14 14:22:44
Message-ID: CAN4CZFM1A3ULtpumPG-rzkr4u5hgCDp9o2XtzRRYMknCQzY0UA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello

I can also confirm the reported case, and also that the attached patch fixes it.

But I also found a few similar cases, that could be fixed together with it.

The first was pointed out by claude:

Take a data directory without backup_label after a crash (such as
pg_ctl stop -m immediate), create recovery.signal and set:

recovery_target = 'immediate'
restore_command = 'false'
recovery_target_action = 'pause'

And then even with 0001, we see:

LOG: starting point-in-time recovery to earliest consistent point
LOG: redo starts at 0/0175BA40
LOG: invalid record length at 0/0177B8B8: expected at least 24, got 0
LOG: consistent recovery state reached at 0/0177B8B8
LOG: redo done at 0/0177B720 ...
FATAL: recovery ended before configured recovery target was reached

This scenario is explicitly mentioned in InitWalRecovery ("Or if you
just kill a running primary server and put it into archive recovery by
creating a recovery signal file"), but doesn't work, even with 0001
applied. An alternative patch fixes this and the original report both:
adding a check right after the main redo loop, before the
recovery_target_action switch.

And then there's a third issue, if instead of immediate, we use fast
in the above repro, which again doesn't work. That needs some
additional changes, and to avoid code duplication, I also did some
refactorings around it.

Additionally, all the above was done on the primary, and we can do the
same tests on a standby, where things are different. One case (backup
on a standby + backup ending in a restore point) requires your fix
from v1, so I think even through the reported case is also fixed by my
version, we need both to cover everything.

Attached is a 2 part series, where 0001 is the same as before, while
0002 adds additional changes and test coverage. We need both patches
for all tests to pass.

Attachment Content-Type Size
v2-0001-Fix-recovery_target-immediate-when-WAL-ends-at-th.patch text/x-patch 2.0 KB
v2-0002-Fix-recovery_target-immediate-without-a-record-to.patch text/x-patch 11.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Joao Rito 2026-11-14 21:33:45 Re: BUG #19807: CHECK constraint not enforced on partitioned table
Previous Message Andrey Rachitskiy 2026-11-14 10:50:33 Re: BUG #19837: ORDER BY/DISTINCT ON use wrong column with grouping set duplicates