Fsync (flush) all inserted WAL records

From: "Vitaly Davydov" <v(dot)davydov(at)postgrespro(dot)ru>
To: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Fsync (flush) all inserted WAL records
Date: 2024-08-06 06:41:12
Message-ID: a5331-66b1c580-3-6e369000@86872474
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi Hackers,

I use async commits. At some moment, I would like to make sure that all inserted WAL records are fsync-ed. I can use XLogFlush function but I have some doubts which LSN to specify. There is a number of functions which return write or insert LSNs but they are not applicable.

I can't use GetXLogInsertRecPtr() because it returns a real insert LSN, not the end LSN of the last record. XLogFlush may fail with such LSN because the specified LSN may be "in the future" if the WAL record ends up to the page boundary (the real insert LSN is summed up with page header size).

I can't use GetXLogWriteRecPtr() because it seems to be bounded to page boundaries. Some inserted WAL records may not be fsync-ed. Some other functions seems not applicable as well.

The first idea is to use GetLastImportantRecPtr() but this function returns the start LSN of the last important WAL record. I would use XLogFlush(GetLastImportantRecPtr() + 1) but I'm not sure that this way is conventional.

Another idea is to create a new function like GetXLogInsertRecPtr() which calls XLogBytePosToEndRecPtr() instead of XLogBytePosToRecPtr() inside it.

Could you please advice which way to go?

With best regards,
Vitaly

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-08-06 07:04:01 Re: remove volatile qualifiers from pg_stat_statements
Previous Message Michael Paquier 2024-08-06 06:28:18 Re: BlastRADIUS mitigation