On Fri, Apr 8, 2022 at 9:31 AM Bharath Rupireddy <bharath.rupireddyforpostg...@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. -- Robert Haas EDB: http://www.enterprisedb.com