10

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?

Egor
  • 523
  • 4
  • 15
  • See [max_slot_wal_keep_size](https://www.postgresql.org/docs/14/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE). As I read it `restart_lsn` and `max_slot_wal_keep_size` work as a safety valve. If a consumer of WAL's gets too far behind and WAL's start stacking up then some of them start getting pruned based on the combination of values. – Adrian Klaver Feb 03 '22 at 16:49

1 Answers1

11

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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • In case when consumer constantly read data from slot - will the value `(confirmed_flush_lsn - restart_lsn)` be pretty the same or it will raise with the amount of logs which have bean already read? – Egor Feb 04 '22 at 07:51
  • It will rise, but then it will shrink again as `restart_lsn` is advanced. – Laurenz Albe Feb 04 '22 at 07:53