On Mon, Dec 5, 2022 at 6:34 AM Michael Paquier <[email protected]> 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
