diff --git a/doc/src/sgml/ref/create_subscription.sgml b/doc/src/sgml/ref/create_subscription.sgml index 2c91eb6..b3a493f 100644 --- a/doc/src/sgml/ref/create_subscription.sgml +++ b/doc/src/sgml/ref/create_subscription.sgml @@ -145,9 +145,10 @@ CREATE SUBSCRIPTION subscription_nameslot_name is set to NONE, there will be no replication slot associated with the subscription. This can be used if the - replication slot will be created later manually. Such - subscriptions must also have both enabled and - create_slot set to false. + replication slot will be created later manually. Setting this + to NONE will change default values of + enabled and create_slot + to false. diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 304ac84..bd667bb 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -199,7 +199,7 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given, /* * Do additional checking for disallowed combination when - * slot_name = NONE was used. + * slot_name = NONE was used, and do additional processing. */ if (slot_name && *slot_name_given && !*slot_name) { @@ -212,6 +212,12 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given, ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("slot_name = NONE and create slot are mutually exclusive options"))); + + /* Change the defaults of other options. */ + if (create_slot) + *create_slot = false; + if (enabled) + *enabled = false; } } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index f7b2840..9085665 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -3832,7 +3832,10 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo) } appendPQExpBuffer(query, " PUBLICATION %s WITH (connect = false, slot_name = ", publications->data); - appendStringLiteralAH(query, subinfo->subslotname, fout); + if (subinfo->subslotname[0] == '\0') + appendPQExpBufferStr(query, "NONE"); + else + appendStringLiteralAH(query, subinfo->subslotname, fout); if (strcmp(subinfo->subsynccommit, "off") != 0) appendPQExpBuffer(query, ", synchronous_commit = %s", fmtId(subinfo->subsynccommit)); diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index 10c3644..8a3cb53 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -49,6 +49,26 @@ SET SESSION AUTHORIZATION 'regress_subscription_user'; ALTER SUBSCRIPTION testsub CONNECTION 'foobar'; ERROR: invalid connection string syntax: missing "=" after "foobar" in connection info string +-- fail - invalid option combination +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true); +ERROR: noconnect and copy data are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true); +ERROR: noconnect and enabled are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true); +ERROR: noconnect and create slot are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true); +ERROR: slot_name = NONE and enabled are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true); +ERROR: slot_name = NONE and create slot are mutually exclusive options +-- ok - with slot_name = NONE +CREATE SUBSCRIPTION nonesub CONNECTION 'dbname=doesnotexits' PUBLICATION testpub WITH (slot_name = NONE, connect = false); +WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables +-- fail +ALTER SUBSCRIPTION nonesub ENABLE; +ERROR: cannot enable subscription that does not have a slot name +ALTER SUBSCRIPTION nonesub REFRESH PUBLICATION; +ERROR: ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions +DROP SUBSCRIPTION nonesub; \dRs+ List of subscriptions Name | Owner | Enabled | Publication | Synchronous commit | Conninfo diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index 798bb0d..29fa462 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -41,6 +41,21 @@ SET SESSION AUTHORIZATION 'regress_subscription_user'; -- fail - invalid connection string ALTER SUBSCRIPTION testsub CONNECTION 'foobar'; +-- fail - invalid option combination +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true); + +-- ok - with slot_name = NONE +CREATE SUBSCRIPTION nonesub CONNECTION 'dbname=doesnotexits' PUBLICATION testpub WITH (slot_name = NONE, connect = false); +-- fail +ALTER SUBSCRIPTION nonesub ENABLE; +ALTER SUBSCRIPTION nonesub REFRESH PUBLICATION; + +DROP SUBSCRIPTION nonesub; + \dRs+ ALTER SUBSCRIPTION testsub SET PUBLICATION testpub2, testpub3 SKIP REFRESH;