Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4d8489f

Browse files
author
Amit Kapila
committed
Prohibit altering invalidated replication slots.
ALTER_REPLICATION_SLOT for invalid replication slots should not be allowed because there is no way to get back the invalidated (logical) slot to work. Author: Bharath Rupireddy Reviewed-by: Peter Smith, Shveta Malik Discussion: https://www.postgresql.org/message-id/CALj2ACW4fSOMiKjQ3=2NVBMTZRTG8Ujg6jsK9z3EvOtvA4vzKQ@mail.gmail.com
1 parent 7b1ddba commit 4d8489f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/backend/replication/slot.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,13 @@ ReplicationSlotAlter(const char *name, const bool *failover,
820820
errmsg("cannot use %s with a physical replication slot",
821821
"ALTER_REPLICATION_SLOT"));
822822

823+
if (MyReplicationSlot->data.invalidated != RS_INVAL_NONE)
824+
ereport(ERROR,
825+
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
826+
errmsg("cannot alter invalid replication slot \"%s\"", name),
827+
errdetail("This replication slot has been invalidated due to \"%s\".",
828+
SlotInvalidationCauses[MyReplicationSlot->data.invalidated]));
829+
823830
if (RecoveryInProgress())
824831
{
825832
/*

src/test/recovery/t/035_standby_logical_decoding.pl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ sub wait_until_vacuum_can_remove
495495
# Scenario 1: hot_standby_feedback off and vacuum FULL
496496
#
497497
# In passing, ensure that replication slot stats are not removed when the
498-
# active slot is invalidated.
498+
# active slot is invalidated, and check that an error occurs when
499+
# attempting to alter the invalid slot.
499500
##################################################
500501

501502
# One way to produce recovery conflict is to create/drop a relation and
@@ -526,6 +527,15 @@ sub wait_until_vacuum_can_remove
526527
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
527528
check_slots_conflict_reason('vacuum_full_', 'rows_removed');
528529

530+
# Attempting to alter an invalidated slot should result in an error
531+
($result, $stdout, $stderr) = $node_standby->psql(
532+
'postgres',
533+
qq[ALTER_REPLICATION_SLOT vacuum_full_inactiveslot (failover);],
534+
replication => 'database');
535+
ok($stderr =~ /ERROR: cannot alter invalid replication slot "vacuum_full_inactiveslot"/ &&
536+
$stderr =~ /DETAIL: This replication slot has been invalidated due to "rows_removed"./,
537+
"invalidated slot cannot be altered");
538+
529539
# Ensure that replication slot stats are not removed after invalidation.
530540
is( $node_standby->safe_psql(
531541
'testdb',

0 commit comments

Comments
 (0)