Re: pg_split_walfile_name

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Fabrice Chapuis <fabrice636861(at)gmail(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: pg_split_walfile_name
Date: 2025-08-12 17:34:56
Message-ID: aJt7QFz2g1VUbZFm@momjian.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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 <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Laurenz Albe 2025-08-13 05:09:21 Re: Re: DB size value different than "/data" dir size
Previous Message Ron Johnson 2025-08-11 16:26:42 Re: Post Oracle to Postgres migartion