pg_walfile_name uses XLByteToPrevSeg - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject pg_walfile_name uses XLByteToPrevSeg
Date
Msg-id CAExHW5uPqLh4627AXn6BD5TXsayEv2+xov66eGDtAuHVFuKD+Q@mail.gmail.com
Whole thread Raw
Responses Re: pg_walfile_name uses XLByteToPrevSeg  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: make MaxBackends available in _PG_init
Next
From: Robert Haas
Date:
Subject: Re: Extensible Rmgr for Table AMs