Re: why pg_walfile_name() cannot be executed during recovery? - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: why pg_walfile_name() cannot be executed during recovery?
Date
Msg-id CALj2ACU0SQYHaX1r2C1syaQjqH=Q8kCZqz1+aBHtJ-4vCJHiUw@mail.gmail.com
Whole thread Raw
In response to Re: why pg_walfile_name() cannot be executed during recovery?  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: why pg_walfile_name() cannot be executed during recovery?  (Andrey Borodin <x4mmm@yandex-team.ru>)
List pgsql-hackers
On Fri, Apr 8, 2022 at 7:28 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Fri, Apr 8, 2022 at 9:31 AM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
> > Fundamental question - should the pg_walfile_{name, name_offset} check
> > whether the file with the computed WAL file name exists on the server
> > right now or ever existed earlier? Right now, they don't do that, see
> > [1].
>
> I don't think that checking whether the file exists is the right
> approach. However, I do think that it's important to be precise about
> which TLI is going to be used. I think it would be reasonable to
> redefine this function (on both the primary and the standby) so that
> the TLI that is used is the one that was in effect at the time record
> at the given LSN was either written or replayed. Then, you could
> potentially use this function to figure out whether you still have the
> WAL files that are needed to replay up to some previous point in the
> WAL stream. However, what about the segments where we switched from
> one TLI to the next in the middle of the segment? There, you probably
> need both the old and the new segments, or maybe if you're trying to
> stream them you only need the new one because we have some weird
> special case that will send the segment from the new timeline when the
> segment from the old timeline is requested. So you couldn't just call
> this function on one LSN per segment and call it good, and it wouldn't
> necessarily be the case that the filenames you got back were exactly
> the ones you needed.
>
> So I'm not entirely sure this proposal is good enough, but it at least
> would have the advantage of meaning that the filename you get back is
> one that existed at some point in time and somebody used it for
> something.

Using insert tli when not in recovery and using tli of the last WAL
replayed record in crash/archive/standby recovery, seems a reasonable
choice to me. I've also added a note in the docs.

Attaching v2 with the above change. Please review it further.

Regards,
Bharath Rupireddy.

Attachment

pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Commitfest wrapup
Next
From: Tom Lane
Date:
Subject: Re: How about a psql backslash command to show GUCs?