Re: Don't keep closed WAL segment in page cache after replay

Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>

From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
To: Kirill Reshke <reshkekirill@gmail.com>
Cc: Fujii Masao <masao.fujii@oss.nttdata.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2026-02-18T09:51:59Z
Lists: pgsql-hackers

Attachments

Thanks for the review!

On Tue, Feb 17, 2026 at 9:38 AM Kirill Reshke <reshkekirill@gmail.com> wrote:
> This does not immediately strike me as good reasoning. We have, for
> example, pg_stat_get_wal_senders (or WalSndInitStopping from
> walsenders.h) function which accesses exactly WalSndCtl->walsnds.
> Why don't we simply have another utility function that will return the
> number of active walsenders?

That's true it is an option. I've switched to this approach and
created a WalSndRunning. We only need to know if there's at least one
wal sender running, no need to have a precise number.

I've also added StandbyMode as a condition to restrict this to
replicas. XLogPageRead may be used by the primary when starting up,
and will likely re-read the WAL so releasing cached pages should be
avoided on the primary.