public inbox for [email protected]  
help / color / mirror / Atom feed
From: Phillip Diffley <[email protected]>
To: [email protected]
Subject: Replication slot WAL reservation
Date: Tue, 25 Mar 2025 11:56:39 -0500
Message-ID: <CAGAwPgR=B9VTDwKkHZRHjYTmQzvJ+30mK-uyc7MMw6Tf9s9Fsw@mail.gmail.com> (raw)

I am trying to understand how logical replication slots work, specifically
in regard to how WAL is reserved and freed by a replication slot.

My current understanding of the WAL (set to wal_level logical) is that:
1. Every DML operation (insert, update, delete, truncate) will have a row
in the WAL and that row will have an LSN assigned to it.
2. The LSNs are assigned when the operation happens.
3. Operations within a transaction are written to the WAL in a contiguous
block when the transaction commits.
4. Each transaction block in the WAL has a commit timestamp associated with
it, and these timestamps are monotonically increasing (I'm only inferring
this, so please correct me if this is not always the case).

A result of an operation being assigned an LSN when the operation occurs
but not being recorded to the WAL until it's transaction commits is that
LSNs in the WAL are not necessarily in order.

But when processing data from a replication slot, we confirm rows that have
been processed and can be deleted from the WAL based on the LSN (eg. with
pg_replication_slot_advance). How does postgres identify what parts of the
WAL can be freed?


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Replication slot WAL reservation
  In-Reply-To: <CAGAwPgR=B9VTDwKkHZRHjYTmQzvJ+30mK-uyc7MMw6Tf9s9Fsw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox