Re: Use fadvise in wal replay - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: Use fadvise in wal replay
Date
Msg-id CALj2ACXNM40VEkiqkinMNg4mET5u5VG=hNYDNoOLi0B4UVUVEA@mail.gmail.com
Whole thread Raw
In response to Re: Use fadvise in wal replay  (Thomas Munro <thomas.munro@gmail.com>)
List pgsql-hackers
On Tue, Jun 21, 2022 at 4:22 PM Thomas Munro <thomas.munro@gmail.com> wrote:
>
> On Tue, Jun 21, 2022 at 10:33 PM Jakub Wartak <Jakub.Wartak@tomtom.com> wrote:
> > > > Maybe the important question is why would be readahead mechanism be
> > > disabled in the first place via /sys | blockdev ?
> > >
> > > Because database should know better than OS which data needs to be
> > > prefetched and which should not. Big OS readahead affects index scan
> > > performance.
> >
> > OK fair point, however the patch here is adding 1 syscall per XLOG_BLCKSZ which is not cheap either. The code is
alreadyhot and there is example from the past where syscalls were limiting the performance [1]. Maybe it could be
prefetchingin larger batches (128kB? 1MB? 16MB?)  ? 
>
> I've always thought we'd want to tell it about the *next* segment
> file, to smooth the transition from one file to the next, something
> like the attached (not tested).

Yes, it makes sense to prefetch the "future" WAL files that "may be"
needed for recovery (crash recovery/archive or PITR recovery/standby
recovery), not the current WAL file. Having said that, it's not a
great idea (IMO) to make the WAL readers prefetching instead WAL
prefetching can be delegated to a new background worker or existing bg
writer or checkpointer which gets started during recovery.

Also, it's a good idea to measure the benefits with and without WAL
prefetching for all recovery types - crash recovery/archive or PITR
recovery/standby recovery. For standby recovery,  the WAL files may be
in OS cache if there wasn't a huge apply lag.

Regards,
Bharath Rupireddy.



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Is RecoveryConflictInterrupt() entirely safe in a signal handler?
Next
From: Amit Kapila
Date:
Subject: Re: Use fadvise in wal replay