Re: pg_rewind reports "no rewind required" due to stale minRecoveryPoint

From: surya poondla <suryapoondla4(at)gmail(dot)com>
To: jan(at)planetscale(dot)com
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Osama Abdul Qader <osamaabdulqaderpostgres(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, hlinnaka(at)iki(dot)fi, shihao zhong <zhong950419(at)gmail(dot)com>
Subject: Re: pg_rewind reports "no rewind required" due to stale minRecoveryPoint
Date: 2026-12-05 22:06:56
Message-ID: CAOVWO5ptXa_oG4KFS54o1AEe9B=YgWt+tR0RfkoReQ107VSDcA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Jan,

Thanks for the patch.
I tested v1 on current master (c061fd5547e), along with Zsolt's PoC, using
a primary with two streaming standbys (S1 promoted; unless noted, S2
replays WAL that only it sees, then is stopped cleanly).

A couple of points
1. v1 fixes the reported case. On master, pg_rewind says "no rewind
required" and S2 then stays stuck with "new timeline 2 forked off ...
before current recovery point". The same happens when the only records S2
replays past the fork are PREPARE TRANSACTION, pg_create_restore_point(),
pg_switch_wal(), or a non-transactional pg_logical_emit_message(); with
hot_standby = off; and when S2 stops by itself at a restore point past the
fork with recovery_target_action = shutdown. When S2 gets its WAL only from
the archive, its minRecoveryPoint ends up almost a full WAL segment behind
the fork, and a cassert pg_rewind fails Assert(target_wal_endrec ==
divergerec). With v1, pg_rewind rewinds in all of them, and S2 then follows
S1, with the same row count where I could query it. A standby stopped
exactly at the fork still gets "no rewind required".

2. The hot_standby = off case no longer reproduces on master. Jeff's
8303f2e13c5 ("Recovery: ensure CLOG updates wait for minRecoveryPoint",
backpatched to 15) switched xact_redo_commit() to
TransactionIdAsyncCommitTree() when hot standby is disabled. With PREPARE
done before S2's restart and only COMMIT PREPARED replayed past the fork,
pg_rewind reports "no rewind required" only with 8303f2e13c5 reverted;
current master rewinds. I haven't tested the --source-pgdata patch, but
since the pg_xact page now carries the commit LSN, I don't think that case
still shows it needs this change. Is there another one that does?

3. As you said, v1 doesn't cover WAL that was received but not replayed,
and a common form of that is a delayed standby. With
recovery_min_apply_delay set on S2, and a commit as the first record after
the fork, S2 receives the post-fork WAL but stops replaying at the fork.
pg_rewind then reports "no rewind required" on both master and v1, and
after a restart S2 waits at the fork to apply the delayed commit instead of
following S1. With S2's replay paused before the fork instead, a cassert
pg_rewind fails the same Assert on both. Zsolt's PoC on its own rewinds
both of these and every case in 1, with no false positive at the fork.
Given the objections on Adam's thread [1], it would help to spell out what
the server change gives us that reading the target's WAL doesn't.

A few smaller things:
1) A behavior change worth noting in the commit message: if S2 is restarted
against the new primary without pg_rewind and with 00000002.history already
in its pg_wal, master loops on "record with incorrect prev-link", while v1
refuses to start with "requested timeline 2 does not contain minimum
recovery point ... on timeline 1". I think that's better, but it is a
change.
2) In the test, it would help to explain why S2 is restarted. Writing out a
page whose LSN is past minRecoveryPoint advances it to the replay position,
not only to that page's LSN, so a page modified by replay and written out
at shutdown hides the problem. That's also why it only happens sometimes.
3) Is this meant for back branches?

[1] https://postgr.es/m/aczc9cxkr7SEHXV5@MAC-CVW1VHW5R6

Regards,
Surya Poondla

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-12-05 22:33:11 Re: Making type Datum be 8 bytes everywhere
Previous Message Tomas Vondra 2026-12-05 21:57:20 Re: extremely slow planner when DISTINCT clause holds more columns