BUG #19975: ALTER SUBSCRIPTION ... SET (slot_name, failover) updates the old slot

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: rushsky518(at)gmail(dot)com
Subject: BUG #19975: ALTER SUBSCRIPTION ... SET (slot_name, failover) updates the old slot
Date: 2026-12-03 08:23:02
Message-ID: 19975-c35e4d582fa4cca0@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19975
Logged by: Zejiang Zhang
Email address: rushsky518(at)gmail(dot)com
PostgreSQL version: 19.0
Operating system: x86_64, rockey linux
Description:

Hi,

ALTER SUBSCRIPTION ... SET (slot_name = 'new_slot', failover = true)
switches the subscription to new_slot, but applies failover to the old
slot.
The subscription then reports failover = true while new_slot still has
failover = false.

Both clusters: wal_level = logical, max_replication_slots = 10.

Publisher:

CREATE TABLE t (id int PRIMARY KEY);
CREATE PUBLICATION p FOR TABLE t;
SELECT pg_create_logical_replication_slot('old_slot', 'pgoutput');
SELECT pg_create_logical_replication_slot('new_slot', 'pgoutput');

Subscriber:

CREATE TABLE t (id int PRIMARY KEY);

CREATE SUBSCRIPTION s
CONNECTION 'host=/tmp/pgpubsub-test/sock port=55440 user=postgres
dbname=postgres'
PUBLICATION p
WITH (slot_name = 'old_slot',
create_slot = false,
copy_data = false,
enabled = false,
password_required = false);

ALTER SUBSCRIPTION s DISABLE;
ALTER SUBSCRIPTION s SET (slot_name = 'new_slot', failover = true);

Actual:

SELECT subslotname, subfailover FROM pg_subscription WHERE subname =
's';
new_slot | t

SELECT slot_name, failover FROM pg_replication_slots
WHERE slot_name IN ('old_slot', 'new_slot') ORDER BY 1;
new_slot | f
old_slot | t

Expected: either the command errors out, or new_slot gets failover = true
and old_slot is left alone.

Cause: AlterSubscription() reads the Subscription before applying the
option
changes (subscriptioncmds.c:1780). update_failover is set at 2019 and
the
pg_subscription row is updated with the new slot name, but the final
walrcv_alter_slot() at 2589 uses sub->slotname, which is still the old
name.
There is no check rejecting slot_name + failover in one command.

Workaround: split it into two ALTERs while the subscription is disabled:

ALTER SUBSCRIPTION s SET (slot_name = 'new_slot');
ALTER SUBSCRIPTION s SET (failover = true);

Fix: reject the combination:

if (update_failover &&
IsSet(opts.specified_opts, SUBOPT_SLOT_NAME))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"slot_name\" and \"failover\" cannot be altered
at the same time")));

A test can go in src/test/recovery/t/040_standby_failover_slots_sync.pl.

Reproduced on 20devel at dc168a83874. The same code pattern appears in
REL_18_STABLE and REL_19_STABLE by inspection, but I did not run the
repro
there.

Regards,

Browse pgsql-bugs by date

  From Date Subject
Next Message Ishjaap Singh 2026-12-03 08:34:14 Re: BUG #19835: view with GROUP BY ROLLUP over duplicate columns changes results after dump/restore
Previous Message Gyorgy Bolyki 2026-12-03 07:50:38 Re: Logical replication: replicated TRUNCATE crash-loops a subscriber with a foreign partition lacking TRUNCATE support