public inbox for [email protected]  
help / color / mirror / Atom feed
From: Christophe Pettus <[email protected]>
To: Phillip Diffley <[email protected]>
Cc: [email protected]
Subject: Re: Replication slot WAL reservation
Date: Tue, 25 Mar 2025 10:13:35 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAGAwPgR=B9VTDwKkHZRHjYTmQzvJ+30mK-uyc7MMw6Tf9s9Fsw@mail.gmail.com>
References: <CAGAwPgR=B9VTDwKkHZRHjYTmQzvJ+30mK-uyc7MMw6Tf9s9Fsw@mail.gmail.com>

Missed this question!

> On Mar 25, 2025, at 09:56, Phillip Diffley <[email protected]> wrote:
> 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?

Basically, if no part of the system "needs" a particular LSN position, the segments that include that LSN position and earlier can be free.

The various things that can "need" a particular LSN point are:

1. Replication slots, if the other side has not confirmed that it has received it (under whatever synchronous commit rules that slot is operating under).
2. The wal_keep_size setting.
3. The max_wal_size setting.
4. The archive_command, if a WAL segment hasn't been successfully archived yet.

One thing to remember is that the WAL does *not* contain contiguous blocks of operations for a single transaction.  The operations are written to the WAL by every session as they do operations, so the WAL is a jumble of different transactions.  One of the jobs of the logical replication framework is to sort that out so it can present only the operations that belong to committed transactions to the output plugin.  (This is why there's an internal structure called the "reorder buffer": it reorders WAL operations into transaction blocks.)





view thread (2+ messages)  latest in thread

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], [email protected]
  Subject: Re: Replication slot WAL reservation
  In-Reply-To: <[email protected]>

* 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