public inbox for [email protected]  
help / color / mirror / Atom feed
From: Masahiko Sawada <[email protected]>
To: [email protected]
Subject: pgsql: pg_upgrade: Optimize logical replication slot caught-up check.
Date: Thu, 05 Feb 2026 01:11:51 +0000
Message-ID: <[email protected]> (raw)

pg_upgrade: Optimize logical replication slot caught-up check.

Commit 29d0a77fa6 improved pg_upgrade to allow migrating logical slots
provided that all logical slots have caught up (i.e., they have no
pending decodable WAL records). Previously, this verification was done
by checking each slot individually, which could be time-consuming if
there were many logical slots to migrate.

This commit optimizes the check to avoid reading the same WAL stream
multiple times. It performs the check only for the slot with the
minimum confirmed_flush_lsn and applies the result to all other slots
in the same database. This limits the check to at most one logical
slot per database.

During the check, we identify the last decodable WAL record's LSN to
report any slots with unconsumed records, consistent with the existing
error reporting behavior. Additionally, the maximum
confirmed_flush_lsn among all logical slots on the database is used as
an early scan cutoff; finding a decodable WAL record beyond this point
implies that no slot has caught up.

Performance testing demonstrated that the execution time remains
stable regardless of the number of slots in the database.

Note that we do not distinguish slots based on their output plugins. A
hypothetical plugin might use a replication origin filter that filters
out changes from a specific origin. In such cases, we might get a
false positive (erroneously considering a slot caught up). However,
this is safe from a data integrity standpoint, such scenarios are
rare, and the impact of a false positive is minimal.

This optimization is applied only when the old cluster is version 19
or later.

Bump catalog version.

Reviewed-by: Chao Li <[email protected]>
Reviewed-by: shveta malik <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Discussion: https://postgr.es/m/CAD21AoBZ0LAcw1OHGEKdW7S5TRJaURdhEk3CLAW69_siqfqyAg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7a1f0f8747a7f7491702be88570a8e4d33686d76

Modified Files
--------------
src/backend/replication/logical/logical.c  |  38 ++++++++---
src/backend/utils/adt/pg_upgrade_support.c |  14 ++--
src/bin/pg_upgrade/check.c                 |   2 +-
src/bin/pg_upgrade/info.c                  | 105 +++++++++++++++++++++--------
src/bin/pg_upgrade/t/003_logical_slots.pl  |  25 ++++---
src/include/catalog/catversion.h           |   2 +-
src/include/catalog/pg_proc.dat            |   6 +-
src/include/replication/logical.h          |   3 +-
8 files changed, 140 insertions(+), 55 deletions(-)



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: pgsql: pg_upgrade: Optimize logical replication slot caught-up check.
  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