Re: Add LSN along with offset to error messages reported for WAL file read/write/validate header failures

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Maxim Orlov <orlovmg(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add LSN along with offset to error messages reported for WAL file read/write/validate header failures
Date: 2022-12-05 03:18:25
Message-ID: CALj2ACUNgDhPH99=kNrdgm-UUYP3=i0aH4fS8iK6qC=v1gMDrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 5, 2022 at 6:34 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> Regarding pg_walfile_offset_lsn(), I am not sure that this is the best
> move we can do as it is possible to compile a LSN from 0/0 with just a
> segment number, say:
> select '0/0'::pg_lsn + :segno * setting::int + :offset
> from pg_settings where name = 'wal_segment_size';

Nice.

> + resultTupleDesc = CreateTemplateTupleDesc(2);
> + TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "lsn",
> + PG_LSNOID, -1, 0);
> + TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "timeline_id",
> + INT4OID, -1, 0);
> Let's use get_call_result_type() to get the TupleDesc and to avoid a
> duplication between pg_proc.dat and this code.
>
> Hence I would tend to let XLogFromFileName do the job, while having a
> SQL function that is just a thin wrapper around it that returns the
> segment TLI and its number, leaving the offset out of the equation as
> well as this new XLogIdFromFileName().

So, a SQL function pg_dissect_walfile_name (or some other better name)
given a WAL file name returns the tli and seg number. Then the
pg_walfile_offset_lsn can just be a SQL-defined function (in
system_functions.sql) using this new function and pg_settings. If this
understanding is correct, it looks good to me at this point.

That said, let's also hear from others.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-12-05 03:29:45 Re: Avoid streaming the transaction which are skipped (in corner cases)
Previous Message Thomas Munro 2022-12-05 03:12:07 Re: Collation version tracking for macOS