Re: Fsync (flush) all inserted WAL records - Mailing list pgsql-hackers

From Vitaly Davydov
Subject Re: Fsync (flush) all inserted WAL records
Date
Msg-id ae3d1-66b37980-5-11516e80@151277688
Whole thread Raw
In response to Re: Fsync (flush) all inserted WAL records  (Aleksander Alekseev <aleksander@timescale.com>)
Responses Re: Fsync (flush) all inserted WAL records
List pgsql-hackers
Hi Aleksander,

On Wednesday, August 07, 2024 12:19 MSK, Aleksander Alekseev <aleksander@timescale.com> wrote:
 
> Does pg_current_wal_flush_lsn() [1] return what you need?
>
> [1]: https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-RECOVERY-CONTROL

If not, take a look at its implementation and functions around,
GetInsertRecPtr() and others. I believe you will find all you need for
the task.
Thank you for the response. I need the LSN of the last inserted by not flushed WAL record. The function pg_current_wal_flush_lsn() doesn't help. It returns the current flush position. GetInsertRecPtr() doesn't help as well because it returns XLogCtl->LogwrtRqst.Write which is updated when the record crosses page boundary. I looked at the code and haven't found any suitable function except of GetLastImportantRecPtr() but it returns start LSN of the last inserted important record (but I need end lsn).

I would propose a new function to fulfill my requirements like this (see below) but I prefer not to create new functions unreasonably:

XLogRecPtr
GetXLogLastInsertEndRecPtr(void)
{
    XLogCtlInsert *Insert = &XLogCtl->Insert;
    uint64 current_bytepos;
    SpinLockAcquire(&Insert->insertpos_lck);
    current_bytepos = Insert->CurrBytePos;
    SpinLockRelease(&Insert->insertpos_lck);
    return XLogBytePosToEndRecPtr(current_bytepos);
}
​​​​​

This function differs from the existing GetXLogInsertRecPtr() by calling XLogBytePosToEndRecPtr instead of XLogBytePosToRecPtr

With best regards,
Vitaly

pgsql-hackers by date:

Previous
From: Amul Sul
Date:
Subject: Re: pg_verifybackup: TAR format backup verification
Next
From: Joe Conway
Date:
Subject: Re: Remaining dependency on setlocale()