Re: pg_walinspect: add functions to locate and list WAL by time and LSN

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_walinspect: add functions to locate and list WAL by time and LSN
Date: 2026-11-24 06:38:53
Message-ID: 5B944421-D872-4BC4-A5C6-F5F1EC037274@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 24, 2026, at 07:57, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Tue, Nov 17, 2026 at 7:17 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>>
>>>> During HOW2026 in Jinan this April, a DBA talked to me that PG lacks an easy way to locate WAL files by time.
>>>
>>> I think using the existing pg_walinspect functions, one can look up
>>> the times using the transaction commit/abort time from the description
>>> column, starting from the last checkpoint's redo LSN till the current
>>> flush LSN. Isn't this helpful? It takes a bit of time to do so, but
>>> that should be fine.
>>
>> I'm afraid that's not easy.
>
> I see the value here, and I'm not against the use case. I'm just not
> yet convinced it needs new functions in pg_walinspect. Would something
> like the attached work? For WAL in pg_wal, the SQL starts from the
> oldest kept WAL or the last checkpoint record and reports the time,
> LSN etc. And for WAL in the archive, pg_waldump can do something
> similar with output filtering.
>

Hi Bharath,

Thanks for the example. I checked your script, and I think it answers a slightly different question. It starts from the checkpoint’s redo LSN or the slot’s restart LSN and looks for the first DELETE on table t. It then scans forward to find the transaction’s COMMIT record and show its commit time. If there were several deletes on that table, the first one it finds might be unrelated to the incident.

In the case the DBAs described to me, they may only remember that the incident happened around 1am. That’s why the patch lets them specify before and after intervals around that time. The operation could have been a DELETE, a TRUNCATE, an ALTER TABLE, or something else. The idea is to give them a narrower LSN range so they can dig into the WAL in whatever ways they like, even if they don’t yet know which operation to look for.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-11-24 06:45:36 RE: Injection point: fix race condition between attach and cleanup
Previous Message Ewan Young 2026-11-24 06:27:48 [PATCH] Fix typo "Querys" in a pquery.c comment