Re: Last removed wal segment file

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: mahendrakar s <mahendrakarforpg(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Last removed wal segment file
Date: 2024-12-23 05:16:01
Message-ID: Z2jyEUB01YFeIa-c@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 23, 2024 at 09:22:06AM +0530, mahendrakar s wrote:
> Is there any psql utility function that returns the last removed wal
> segment file?
> I see there is a method: XLogGetLastRemovedSegno in xlog.c.
> Would be happy to add a new psql function around it (similar to:
> pg_walfile_name, pg_last_wal_replay_lsn, etc other utility functions
> we have).

What's your use-case for it? I have to admit that finding out this
information can be a bit annoying as it requires checking the state of
archiving and the replication slots from which you would get a LSN
(not a segment name). Of course, one can use pg_ls_waldir() these
days and it would also work based on timeline number and even partial
segments which are not removed by the checkpointer. That's more
expensive than looking at a single counter in shmem.

If you wrap a SQL function around that, the segment number would not
be enough to guess which segment is removed: the timeline of the file
removed should also be added. Hence XLogCtlData should be extended
with a kind of lastRemovedSegTLI or equivalent to be able to rebuild
the file name from the data in shared memory. Note that
UpdateLastRemovedPtr() extracts the timeline number, does not store
it.

Also, note that UpdateLastRemovedPtr() has a small race condition when
it comes to monitoring: it is called before the file is physically
removed in RemoveOldXlogFiles(). It would not really matter much in
practice, I guess..
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message cca5507 2024-12-23 05:20:21 Re: Fix a wrong comment in load_file()
Previous Message Michael Paquier 2024-12-23 04:56:24 Re: attndims, typndims still not enforced, but make the value within a sane threshold