From 7474167cb21430cbe664a54d7c5345cacfe94518 Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Thu, 3 Dec 2026 12:00:00 -0600 Subject: [PATCH] Validate the default slot name in CREATE SUBSCRIPTION. When slot_name is not given, CREATE SUBSCRIPTION uses the subscription name as the slot name without validating it, while an explicit slot_name is validated. With connect = false, a subscription such as "MySub" could be created whose slot can never be created on the publisher, and pg_dump writes that slot name explicitly, so the dump could not be restored. Validate the default slot name the same way as an explicit one. Author: Baji Shaik --- src/backend/commands/subscriptioncmds.c | 4 ++++ src/test/regress/expected/subscription.out | 4 ++++ src/test/regress/sql/subscription.sql | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index abea2ecd276..a34b4e1f008 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -786,7 +786,11 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, if (!IsSet(opts.specified_opts, SUBOPT_SLOT_NAME) && opts.slot_name == NULL) + { + /* The default slot name must be valid, like an explicit one */ + ReplicationSlotValidateName(stmt->subname, false, ERROR); opts.slot_name = stmt->subname; + } /* The default for synchronous_commit of subscriptions is off. */ if (opts.synchronous_commit == NULL) diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index e09c81b3b2a..4e387afe43a 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -131,6 +131,10 @@ ALTER SUBSCRIPTION regress_testsub3 ENABLE; ERROR: cannot enable subscription that does not have a slot name ALTER SUBSCRIPTION regress_testsub3 REFRESH PUBLICATION; ERROR: ALTER SUBSCRIPTION ... REFRESH PUBLICATION is not allowed for disabled subscriptions +-- fail - the default slot name (the subscription name) must be a valid slot name +CREATE SUBSCRIPTION "Regress_TestSub" CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false); +ERROR: replication slot name "Regress_TestSub" contains invalid character +HINT: Replication slot names may only contain lower case letters, numbers, and the underscore character. -- fail - origin must be either none or any CREATE SUBSCRIPTION regress_testsub4 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false, origin = foo); ERROR: unrecognized origin value: "foo" diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index 4ccce5c56f5..c867667f2f3 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -88,6 +88,9 @@ CREATE SUBSCRIPTION regress_testsub3 CONNECTION 'dbname=regress_doesnotexist' PU ALTER SUBSCRIPTION regress_testsub3 ENABLE; ALTER SUBSCRIPTION regress_testsub3 REFRESH PUBLICATION; +-- fail - the default slot name (the subscription name) must be a valid slot name +CREATE SUBSCRIPTION "Regress_TestSub" CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false); + -- fail - origin must be either none or any CREATE SUBSCRIPTION regress_testsub4 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false, origin = foo); -- 2.54.0 (Apple Git-157)