Subject: pgsql: Restrict copying of invalidated replication slots.

From: Masahiko Sawada <[email-masked]>
Date: Thu, 03 Apr 2025 17:30:32 +0000

Restrict copying of invalidated replication slots.

Previously, invalidated logical and physical replication slots could
be copied using the pg_copy_logical_replication_slot and
pg_copy_physical_replication_slot functions. Replication slots that
were invalidated for reasons other than WAL removal retained their
restart_lsn. This meant that a new slot copied from an invalidated
slot could have a restart_lsn pointing to a WAL segment that might
have already been removed.

This commit restricts the copying of invalidated replication slots.

Backpatch to v16, where slots could retain their restart_lsn when
invalidated for reasons other than WAL removal.

For v15 and earlier, this check is not required since slots can only
be invalidated due to WAL removal, and existing checks already handle
this issue.

Author: Shlok Kyal <[email-masked]>
Reviewed-by: vignesh C <[email-masked]>
Reviewed-by: Zhijie Hou <[email-masked]>
Reviewed-by: Peter Smith <[email-masked]>
Reviewed-by: Masahiko Sawada <[email-masked]>
Reviewed-by: Amit Kapila <[email-masked]>
Discussion: https://postgr.es/m/CANhcyEU65aH0VYnLiu%3DOhNNxhnhNhwcXBeT-jvRe1OiJTo_Ayg%40mail.gmail.com
Backpatch-through: 16

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a4309e85f4614315584e67737ea7b5efa19fb24c

Modified Files
--------------
doc/src/sgml/func.sgml                              |  6 ++++--
src/backend/replication/slotfuncs.c                 | 21 +++++++++++++++++++++
src/test/recovery/t/035_standby_logical_decoding.pl |  9 +++++++++
3 files changed, 34 insertions(+), 2 deletions(-)