public inbox for [email protected]  
help / color / mirror / Atom feed
From: Bruce Momjian <[email protected]>
To: Fabrice Chapuis <[email protected]>
Cc: [email protected]
Subject: Re: pg_split_walfile_name
Date: Tue, 12 Aug 2025 13:34:56 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAA5-nLCE4PyT7Dh5ogNwBc=dwdA2T58Kc7uWHN4fW1GmKPAG4w@mail.gmail.com>
References: <CAA5-nLCE4PyT7Dh5ogNwBc=dwdA2T58Kc7uWHN4fW1GmKPAG4w@mail.gmail.com>

On Thu, Jul 31, 2025 at 10:08:25AM +0200, Fabrice Chapuis wrote:
> Hi,
> 
> In the documentation, PostgreSQL: Documentation: 17: 9.28. System
> Administration Functions, I do not understand the position 100C in the wal
> filename and how the result could be C001?
> 
> Any idea?
> 
> Regards,
> 
> Fabrice
> 
> pg_split_walfile_name is useful to compute a LSN from a file offset and WAL
> file name, for example:
> 
> postgres=# \set file_name '000000010000000100C000AB'
> postgres=# \set offset 256
> postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset AS lsn
>   FROM pg_split_walfile_name(:'file_name') pd,
>        pg_show_all_settings() ps
>   WHERE ps.name = 'wal_segment_size';
>       lsn
> ---------------
>  C001/AB000100
> (1 row)

I think your problem is that you are converting the WAL segment/offset
to a number of bytes by multiplying by wal_segment_size, and then you
are casting it to an LSN, which assumes time line/segment number;  try
this:

	SELECT to_hex((pd.segment_number * ps.setting::int + :offset)::bigint) AS lsn
	  FROM pg_split_walfile_name(:'file_name') pd,
	       pg_show_all_settings() ps
	  WHERE ps.name = 'wal_segment_size';
	     lsn
	--------------
	 c001ab000100


-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: pg_split_walfile_name
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox