Re: Use WALReadFromBuffers in more places - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: Use WALReadFromBuffers in more places
Date
Msg-id CALj2ACW4BvWL_PyvS-ZF5Z70bymLPJWLHXVLbGCZoAwjA6EzeA@mail.gmail.com
Whole thread Raw
In response to Re: Use WALReadFromBuffers in more places  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: Use WALReadFromBuffers in more places
List pgsql-hackers
Hi,

On Mon, Sep 22, 2025 at 8:26 AM Jeff Davis <pgsql@j-davis.com> wrote:
>
> On Sat, 2025-09-13 at 22:04 -0700, Bharath Rupireddy wrote:
> > Thanks for looking at this. Yes, the WAL writers can zero out flushed
> > buffers before WALReadFromBuffers gets to them. However,
> > WALReadFromBuffers was intentionally designed as an opportunistic
> > optimization - it's a "try this first, quickly" approach before
> > falling back to reading from WAL files.
>
> IIRC, one motivation (perhaps the primary motivation?) was to make it
> possible to read buffers before they are flushed. It was always
> possible to read already-flushed buffers.
>
> The benefit of reading unflushed buffers is that we can replicate the
> WAL sooner (though it can't be replayed until the primary flushes it).
> Is that right?

Right. Reading unflushed WAL buffers for replication was one of the
motivations. But, in general, WALReadFromBuffers has more benefits
since it lets WAL buffers act as a cache for reads, avoiding the need
to re-read WAL from disk for (both physical and logical) replication.
For example, it makes the use of direct I/O for WAL more realistic and
can provide significant performance benefits [1].

[1] https://www.postgresql.org/message-id/20230114203403.4zpg72fw2qb34awf%40awork3.anarazel.de

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: GNU/Hurd portability patches
Next
From: Tom Lane
Date:
Subject: Re: GNU/Hurd portability patches