Skip to content

Commit 013c117

Browse files
committed
Remove the NODROP SLOT option from DROP SUBSCRIPTION
It turned out this approach had problems, because a DROP command should not have any options other than CASCADE and RESTRICT. Instead, always attempt to drop the slot if there is one configured, but also add an ALTER SUBSCRIPTION action to set the slot to NONE. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com> Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/29431.1493730652@sss.pgh.pa.us
1 parent c4c493f commit 013c117

File tree

20 files changed

+198
-128
lines changed

20 files changed

+198
-128
lines changed

doc/src/sgml/ref/create_subscription.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ CREATE SUBSCRIPTION <replaceable class="PARAMETER">subscription_name</replaceabl
133133
Name of the replication slot to use. The default behavior is to use
134134
<literal>subscription_name</> for slot name.
135135
</para>
136+
137+
<para>
138+
When <literal>SLOT NAME</literal> is set to
139+
<literal>NONE</literal>, there will be no replication slot associated
140+
with the subscription. This can be used if the replication slot will be
141+
created later manually. Such subscriptions must also have both
142+
<literal>ENABLED</literal> and <literal>CREATE SLOT</literal> set
143+
to <literal>false</literal>.
144+
</para>
136145
</listitem>
137146
</varlistentry>
138147

doc/src/sgml/ref/drop_subscription.sgml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ DROP SLOT | NODROP SLOT ]
24+
DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ CASCADE | RESTRICT ]
2525
</synopsis>
2626
</refsynopsisdiv>
2727

@@ -39,7 +39,9 @@ DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable
3939

4040
<para>
4141
<command>DROP SUBSCRIPTION</command> cannot be executed inside a
42-
transaction block when <literal>DROP SLOT</literal> is specified.
42+
transaction block if the subscription is associated with a replication
43+
slot. (You can use <command>ALTER SUBSCRIPTION</command> to unset the
44+
slot.)
4345
</para>
4446
</refsect1>
4547

@@ -57,20 +59,13 @@ DROP SUBSCRIPTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable
5759
</varlistentry>
5860

5961
<varlistentry>
60-
<term><literal>DROP SLOT</literal></term>
61-
<term><literal>NODROP SLOT</literal></term>
62-
<listitem>
63-
<para>
64-
Specifies whether to drop the replication slot on the publisher. The
65-
default is
66-
<literal>DROP SLOT</literal>.
67-
</para>
62+
<term><literal>CASCADE</literal></term>
63+
<term><literal>RESTRICT</literal></term>
6864

65+
<listitem>
6966
<para>
70-
If the publisher is not reachable when the subscription is to be
71-
dropped, then it is useful to specify <literal>NODROP SLOT</literal>.
72-
But the replication slot on the publisher will then have to be removed
73-
manually.
67+
These key words do not have any effect, since there are no dependencies
68+
on subscriptions.
7469
</para>
7570
</listitem>
7671
</varlistentry>

src/backend/catalog/pg_subscription.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ GetSubscription(Oid subid, bool missing_ok)
8282
tup,
8383
Anum_pg_subscription_subslotname,
8484
&isnull);
85-
Assert(!isnull);
86-
sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
85+
if (!isnull)
86+
sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
87+
else
88+
sub->slotname = NULL;
8789

8890
/* Get synccommit */
8991
datum = SysCacheGetAttr(SUBSCRIPTIONOID,
@@ -147,7 +149,8 @@ FreeSubscription(Subscription *sub)
147149
{
148150
pfree(sub->name);
149151
pfree(sub->conninfo);
150-
pfree(sub->slotname);
152+
if (sub->slotname)
153+
pfree(sub->slotname);
151154
list_free_deep(sub->publications);
152155
pfree(sub);
153156
}

0 commit comments

Comments
 (0)