Re: Standby writes pages past minRecoveryPoint after crash recovery

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, Jan Nidzwetzki <jan(at)planetscale(dot)com>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Subject: Re: Standby writes pages past minRecoveryPoint after crash recovery
Date: 2026-12-03 14:32:20
Message-ID: CAHGQGwFGAnwdvJbs3Tj1c9mj8jDNfEH65A41DXM-oWCEUWz_dA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Dec 3, 2026 at 1:09 PM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
> The attached patch clears the flag only in the startup process, and
> adds a TAP test.

Thanks for the report and patch! Your analysis seems correct to me.

With this change, checkpointer (probably and also bgwriter ?) would acquire
ControlFileLock with LW_EXCLUSIVE mode on every call to
UpdateMinRecoveryPoint() during crash recovery, instead of returning
early after the first call. Could this have a performance impact,
or is it not worth worrying about?

ISTM that we could avoid this by taking ControlFileLock with LW_SHARED mode
when LocalMinRecoveryPoint is invalid, before proceeding to the existing path:

if (!XLogRecPtrIsValid(LocalMinRecoveryPoint))
{
if (InRecovery)
{
updateMinRecoveryPoint = false;
return;
}

LWLockAcquire(ControlFileLock, LW_SHARED);
LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
LWLockRelease(ControlFileLock);

if (!XLogRecPtrIsValid(LocalMinRecoveryPoint))
return;
}

Is this worthwhile, or overkill?

Regarding the test change, does the test guarantee that the checkpointer
calls UpdateMinRecoveryPoint() before the startup process switches to
archive recovery? Requesting a restartpoint does not seem to guarantee
that ordering. No? I'm just concerned about that the test may pass without
the fix if the checkpointer runs too late. Thought?

Regards,

--
Fujii Masao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chengpeng Yan 2026-12-03 14:38:53 Re: [PATCH] Avoid copying tuples that a bounded sort will discard
Previous Message brianmacy 2026-12-03 14:21:08 Re: [PATCH v1] Open only the target segment to reach existing blocks