Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ulstp-006pQN-Bp for pgsql-admin@arkaria.postgresql.org; Tue, 12 Aug 2025 17:35:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ulstn-008p69-Ly for pgsql-admin@arkaria.postgresql.org; Tue, 12 Aug 2025 17:34:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ulstn-008p60-AY for pgsql-admin@lists.postgresql.org; Tue, 12 Aug 2025 17:34:59 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ulstl-000DzO-00 for pgsql-admin@lists.postgresql.org; Tue, 12 Aug 2025 17:34:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2025010100; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description; bh=K7QQctfnhetXGebsJBTsArI/xrhXqm37KCqDXU26SU0=; b=eibyHoGTYtY/RYj4xivo6ahGTM i/XWUrxVMFVbbdUAB/Bj/BL4kjLP8CJaDP3Mpbma9GNjzjVTtwSe+NMv4vVAbhYhX5m8S1p9/XH/D SITtDC2kwm70XJH9SJBZvbnzW69mnVL1QOUGJINk0TUDDrdDRsNjuPPz+kjxLNyeN88q4/WAYf9gZ A+mpbA7p3Q5aksiPxM3iw5Ubt4AV6VH97GmARA+cW6rbcdFPwDKPsoY5bKGwsHlkoUCKkFVqZSqHH 8KD8/ZTEnqBmogyKf4DvQKYfqlGtjf92/UdLhSdFV6sJGYsF20EYWCtkpWFOp5OMyDsOdobB3TbEZ 9phVVOeg==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1ulstk-00A9US-2P; Tue, 12 Aug 2025 13:34:56 -0400 Date: Tue, 12 Aug 2025 13:34:56 -0400 From: Bruce Momjian To: Fabrice Chapuis Cc: pgsql-admin@lists.postgresql.org Subject: Re: pg_split_walfile_name Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future.