Hi Aleksander,

On Wednesday, August 07, 2024 12:19 MSK, Aleksander Alekseev 
<aleksan...@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

Reply via email to