Hi All, pg_walfile_name() returns the WAL file name corresponding to the given WAL location. Per https://www.postgresql.org/docs/14/functions-admin.html --- pg_walfile_name ( lsn pg_lsn ) → text
Converts a write-ahead log location to the name of the WAL file holding that location. --- The function uses XLByteToPrevSeg() which gives the name of previous WAL file if the location falls on the boundary of WAL segment. I find it misleading since the given LSN will fall into the segment provided by XLByteToSeg() and not XLBytePrevSeg(). And it gives some surprising results as well --- #select pg_walfile_name('0/0'::pg_lsn); pg_walfile_name -------------------------- 00000001FFFFFFFF000000FF (1 row) ---- Comment in the code says --- /* * Compute an xlog file name given a WAL location, * such as is returned by pg_stop_backup() or pg_switch_wal(). */ Datum pg_walfile_name(PG_FUNCTION_ARGS) --- XLByteToPrevSeg() may be inline with the comment but I don't think that's what is conveyed by the documentation at least. -- Best Wishes, Ashutosh