drop_subscription_wait_issue.patch

application/octet-stream

Filename: drop_subscription_wait_issue.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
doc/src/sgml/ref/create_subscription.sgml 4 4
src/backend/commands/subscriptioncmds.c 1 1
src/bin/pg_dump/t/002_pg_dump.pl 3 3
src/test/regress/expected/subscription.out 2 0
src/test/regress/sql/subscription.sql 2 0
diff --git a/doc/src/sgml/ref/create_subscription.sgml b/doc/src/sgml/ref/create_subscription.sgml
index b8cd15f3280..0086b5a0e79 100644
--- a/doc/src/sgml/ref/create_subscription.sgml
+++ b/doc/src/sgml/ref/create_subscription.sgml
@@ -168,10 +168,10 @@ CREATE SUBSCRIPTION <replaceable class="parameter">subscription_name</replaceabl
         <term><literal>slot_name</literal> (<type>string</type>)</term>
         <listitem>
          <para>
-          Name of the publisher's replication slot to use.  The default is
-          to use the name of the subscription for the slot name. The name cannot
-          be <literal>pg_conflict_detection</literal> as it is reserved for the
-          conflict detection.
+          Name of the publisher's replication slot to use.  When
+          <literal>connect</literal> is enabled, the slot name defaults to the
+          name of the subscription. The name cannot be <literal>pg_conflict_detection</literal>
+          as it is reserved for the conflict detection.
          </para>
 
          <para>
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index cd6c3684482..1d5d3b581f4 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -651,7 +651,7 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt,
 	if (opts.retaindeadtuples)
 		CheckSubDeadTupleRetention(true, !opts.enabled, WARNING);
 
-	if (!IsSet(opts.specified_opts, SUBOPT_SLOT_NAME) &&
+	if (!IsSet(opts.specified_opts, SUBOPT_SLOT_NAME) && opts.connect &&
 		opts.slot_name == NULL)
 		opts.slot_name = stmt->subname;
 
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 6c7ec80e271..a7e0df0f1eb 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -3336,7 +3336,7 @@ my %tests = (
 						 CONNECTION \'dbname=doesnotexist\' PUBLICATION pub1
 						 WITH (connect = false);',
 		regexp => qr/^
-			\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub1', streaming = parallel);\E
+			\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = NONE, streaming = parallel);\E
 			/xm,
 		like => { %full_runs, section_post_data => 1, },
 	},
@@ -3347,7 +3347,7 @@ my %tests = (
 						 CONNECTION \'dbname=doesnotexist\' PUBLICATION pub1
 						 WITH (connect = false, origin = none, streaming = off);',
 		regexp => qr/^
-			\QCREATE SUBSCRIPTION sub2 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub2', streaming = off, origin = none);\E
+			\QCREATE SUBSCRIPTION sub2 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = NONE, streaming = off, origin = none);\E
 			/xm,
 		like => { %full_runs, section_post_data => 1, },
 	},
@@ -3358,7 +3358,7 @@ my %tests = (
 						 CONNECTION \'dbname=doesnotexist\' PUBLICATION pub1
 						 WITH (connect = false, origin = any, streaming = on);',
 		regexp => qr/^
-			\QCREATE SUBSCRIPTION sub3 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = 'sub3', streaming = on);\E
+			\QCREATE SUBSCRIPTION sub3 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (connect = false, slot_name = NONE, streaming = on);\E
 			/xm,
 		like => { %full_runs, section_post_data => 1, },
 	},
diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out
index a98c97f7616..180be3c2bde 100644
--- a/src/test/regress/expected/subscription.out
+++ b/src/test/regress/expected/subscription.out
@@ -343,6 +343,7 @@ CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUB
        WITH (connect = false, create_slot = false, copy_data = false);
 WARNING:  subscription was created, but is not connected
 HINT:  To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription.
+ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub');
 ALTER SUBSCRIPTION regress_testsub ENABLE;
 -- fail - ALTER SUBSCRIPTION with refresh is not allowed in a transaction
 -- block or function
@@ -467,6 +468,7 @@ SET SESSION AUTHORIZATION regress_subscription_user3;
 CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist password=regress_fakepassword' PUBLICATION testpub WITH (connect = false);
 WARNING:  subscription was created, but is not connected
 HINT:  To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription.
+ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub');
 -- we cannot give the subscription away to some random user
 ALTER SUBSCRIPTION regress_testsub OWNER TO regress_subscription_user;
 ERROR:  must be able to SET ROLE "regress_subscription_user"
diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql
index f0f714fe747..7cdd8166b6b 100644
--- a/src/test/regress/sql/subscription.sql
+++ b/src/test/regress/sql/subscription.sql
@@ -228,6 +228,7 @@ DROP SUBSCRIPTION regress_testsub;
 CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION mypub
        WITH (connect = false, create_slot = false, copy_data = false);
 
+ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub');
 ALTER SUBSCRIPTION regress_testsub ENABLE;
 
 -- fail - ALTER SUBSCRIPTION with refresh is not allowed in a transaction
@@ -321,6 +322,7 @@ RESET SESSION AUTHORIZATION;
 GRANT CREATE ON DATABASE REGRESSION TO regress_subscription_user3;
 SET SESSION AUTHORIZATION regress_subscription_user3;
 CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist password=regress_fakepassword' PUBLICATION testpub WITH (connect = false);
+ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'regress_testsub');
 
 -- we cannot give the subscription away to some random user
 ALTER SUBSCRIPTION regress_testsub OWNER TO regress_subscription_user;