From 5a433c051bcec7a0669e185ecf17373026c876c4 Mon Sep 17 00:00:00 2001 From: Ishjaap Singh Date: Sun, 6 Dec 2026 12:00:29 +0000 Subject: [PATCH v1] Disallow altering slot_name and failover at the same time ALTER SUBSCRIPTION ... SET (slot_name = 'new_slot', failover = true) stored the new slot name and the new failover value in pg_subscription, but then changed the failover property of the old slot on the publisher, because walrcv_alter_slot() is called with the slot name read before the command. The subscription then used new_slot while claiming failover = true, and new_slot still had failover = false. Reject the combination, like we already do for slot_name and two_phase. Users can run the two changes as separate commands. --- src/backend/commands/subscriptioncmds.c | 10 ++++++++++ src/test/regress/expected/subscription.out | 3 +++ src/test/regress/sql/subscription.sql | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index abea2ecd276..d5d75a8ae21 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -2039,6 +2039,16 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt, CheckAlterSubOption(sub, "failover", update_failover, isTopLevel); + /* + * The failover option is set on the slot by name, using + * the slot name from before this command, so changing the + * slot name at the same time is not allowed. + */ + if (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"))); + values[Anum_pg_subscription_subfailover - 1] = BoolGetDatum(opts.failover); replaces[Anum_pg_subscription_subfailover - 1] = true; diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index e09c81b3b2a..d5582b9e331 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -656,6 +656,9 @@ BEGIN; ALTER SUBSCRIPTION regress_testsub SET (failover); ERROR: ALTER SUBSCRIPTION ... SET (failover) cannot run inside a transaction block COMMIT; +-- fail - cannot alter slot_name and failover at the same time +ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub_new', failover = true); +ERROR: "slot_name" and "failover" cannot be altered at the same time -- ok, owning it is enough for this stuff ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE); DROP SUBSCRIPTION regress_testsub; diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index 4ccce5c56f5..7a5a5ec97f6 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -504,6 +504,9 @@ BEGIN; ALTER SUBSCRIPTION regress_testsub SET (failover); COMMIT; +-- fail - cannot alter slot_name and failover at the same time +ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub_new', failover = true); + -- ok, owning it is enough for this stuff ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE); DROP SUBSCRIPTION regress_testsub; -- 2.43.0