Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between restart_lsn and confirmed_flush_lsn in Postgresql?

As documentation said - restart_lsn is:

The address (LSN) of oldest WAL which still might be required by the consumer of this slot and thus won't be automatically removed during checkpoints unless this LSN gets behind more than max_slot_wal_keep_size from the current LSN. NULL if the LSN of this slot has never been reserved.

And confirmed_flush_lsn is:

The address (LSN) up to which the logical slot's consumer has confirmed receiving data. Data older than this is not available anymore. NULL for physical slots.

The thing i do not understand (in case of logical slots) is - how do this both properties connected to each other? confirmed_flush_lsn description said that older logs are deleted, but restart_lsn sound like it is not 100% right. If not and there is some number of transaction logs between restart_lsn and confirmed_flush_lsn - how much could this number be? Is it some predefined and immutable value, lets say several MBs or it could it really raise up to max_slot_wal_keep_size? How it is decided - what WAL still might be required by the consumer and what not?

like image 640
Egor Avatar asked Jan 24 '26 08:01

Egor


1 Answers

confirmed_flush_lsn is the latest position in the WAL for which the consumer has already received decoded data, so logical decoding won't emit data for anything earlier than that.

However, logical decoding may still need WAL older than that in order to calculate the required information, WAL from transactions that started before confirmed_flush_lsn. Thus there is restart_lsn, which marks the point from which on the server must retain WAL to be able to continue decoding.

like image 85
Laurenz Albe Avatar answered Jan 27 '26 00:01

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!