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

From: Jan Nidzwetzki <jan(at)planetscale(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Osama Abdul Qader <osamaabdulqaderpostgres(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, hlinnaka(at)iki(dot)fi
Subject: Re: pg_rewind reports "no rewind required" due to stale minRecoveryPoint
Date: 2026-12-01 17:27:28
Message-ID: 3357e42b-2444-4199-803f-a34e8bd32270@planetscale.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Zsolt,

Thanks for the review, for finding Adam's thread, and for the PoC.

On 28.11.26 13:00, Zsolt Parragi wrote:
> Isn't this the same change that Adam Lee proposed in [1] earlier this
> year for recovery_target_action = shutdown? His patch advanced
> minRecoveryPoint to the replay position at every restartpoint and then
> Heikki suggested calling UpdateMinRecoveryPoint(), which is what your
> patch does.

I missed that thread. Yes, it's the same approach, but limited to
shutdown restart points, so a running standby's minRecoveryPoint doesn't
change.

> In that thread Michael and Horiguchi-san argued against it, but this
> could be another example in favor of it.

Agreed, here the stale value makes pg_rewind skip a rewind that is needed.

On Michael's concern about more code paths updating minRecoveryPoint:
CreateRestartPoint() already calls
UpdateMinRecoveryPoint(InvalidXLogRecPtr, true) when it skips the
restart point, and its comment says this is done "so that if this is a
shutdown restart point, we won't start up earlier than before." The
patch applies the same logic when a shutdown restart point is performed.
By then, all buffers have been flushed, so minRecoveryPoint still means
the same thing.

Regarding Horiguchi-san's point that tools using minRecoveryPoint to
check recovery progress would look at the wrong value: for a standby
that stopped cleanly, pg_control has no other value to show how far it
replayed. The other way is to read the WAL, as you mentioned next.

> From a different perspective, isn't this something that could be
> possibly fixed in pg_rewind?

I'd keep the server change and see a fix in pg_rewind as a complement. I
ran the PoC against my test cases, and it rewinds all of them. It also
covers WAL that was received but not replayed, which the server change
alone doesn't. In that case, pg_rewind reports "no rewind required", but
when the standby is started again, it first replays that WAL from its
pg_wal and then can't follow the new timeline. As you suspect below, the
--source-pgdata patch still needs the server change.

> However, looking at your other patch [2]: it uses the minRecoveryPoint
> of a stopped standby as the consistency point for the copied files.
> With hot_standby = off on the source a replayed commit reaches pg_xact
> without moving minRecoveryPoint, so doesn't that patch need this
> server side change? If yes, that's an argument for keeping it, even if
> pg_rewind looks at the target's WAL.

Yes. When hot_standby is off, xact_redo_commit() uses
TransactionIdCommitTree() instead of TransactionIdAsyncCommitTree(), so
the pg_xact page does not get an LSN recorded. I tested this with
--source-pgdata: a transaction inserted a row before the source's last
restart point and committed after it. In the target, the transaction is
committed in pg_xact and the row is visible, even though the target
stops recovery (recovery_target = 'immediate') before the commit record.
With the restart point fix, or with hot_standby = on, the target's
minRecoveryPoint includes the commit. The PoC does not change this,
since it only checks the target's WAL.

Best regards
Jan

--
Jan Nidzwetzki
PlanetScale

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-12-01 17:39:40 Re: Interrupts vs signals
Previous Message Antonin Houska 2026-12-01 17:09:07 Re: Allow progress tracking of sub-commands