]> granicus.if.org Git - postgresql/commitdiff
Add a WAIT option to DROP_REPLICATION_SLOT
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 1 Sep 2017 11:44:14 +0000 (13:44 +0200)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 1 Sep 2017 11:53:34 +0000 (13:53 +0200)
Commit 9915de6c1cb2 changed the default behavior of
DROP_REPLICATION_SLOT so that it would wait until any session holding
the slot active would release it, instead of raising an error.  But
users are already depending on the original behavior, so revert to it by
default and add a WAIT option to invoke the new behavior.

Per complaint from Simone Gotti, in
Discussion: https://postgr.es/m/CAEvsy6Wgdf90O6pUvg2wSVXL2omH5OPC-38OD4Zzgk-FXavj3Q@mail.gmail.com

doc/src/sgml/logicaldecoding.sgml
doc/src/sgml/protocol.sgml
src/backend/commands/subscriptioncmds.c
src/backend/replication/repl_gram.y
src/backend/replication/repl_scanner.l
src/backend/replication/slotfuncs.c
src/backend/replication/walsender.c
src/include/nodes/replnodes.h

index 8dcfc6c742473ac1b3079c3a373b17aaaad4e2bc..f8142518c1571adc03d8c0a8fcb9ff2036f19ec9 100644 (file)
@@ -303,7 +303,7 @@ $ pg_recvlogical -d postgres --slot test --drop-slot
      </listitem>
 
      <listitem>
-      <para><literal>DROP_REPLICATION_SLOT <replaceable>slot_name</replaceable></literal></para>
+      <para><literal>DROP_REPLICATION_SLOT <replaceable>slot_name</replaceable></literal> <optional> <literal>WAIT</> </></para>
      </listitem>
 
      <listitem>
index 7c012f59a3e198efc296cee909bb26d7c24a62e8..2bb4e38a9dbcaf45a58c731a9d7fb085e1f9ca6a 100644 (file)
@@ -2173,13 +2173,13 @@ The commands accepted in walsender mode are:
   </varlistentry>
 
   <varlistentry>
-    <term><literal>DROP_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</>
+    <term>
+     <literal>DROP_REPLICATION_SLOT</literal> <replaceable class="parameter">slot_name</> <optional> <literal>WAIT</> </optional>
      <indexterm><primary>DROP_REPLICATION_SLOT</primary></indexterm>
     </term>
     <listitem>
      <para>
-      Drops a replication slot, freeing any reserved server-side resources. If
-      the slot is currently in use by an active connection, this command fails.
+      Drops a replication slot, freeing any reserved server-side resources.
       If the slot is a logical slot that was created in a database other than
       the database the walsender is connected to, this command fails.
      </para>
@@ -2192,6 +2192,17 @@ The commands accepted in walsender mode are:
          </para>
        </listitem>
       </varlistentry>
+
+      <varlistentry>
+       <term><literal>WAIT</literal></term>
+       <listitem>
+        <para>
+         This option causes the command to wait if the slot is active until
+         it becomes inactive, instead of the default behavior of raising an
+         error.
+        </para>
+       </listitem>
+      </varlistentry>
      </variablelist>
     </listitem>
   </varlistentry>
index 005e74201d477a104a3ab8e9d0e4af7f1b6d4994..77620dfd4296514703195d0e09230fab38cde3b0 100644 (file)
@@ -959,7 +959,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
        load_file("libpqwalreceiver", false);
 
        initStringInfo(&cmd);
-       appendStringInfo(&cmd, "DROP_REPLICATION_SLOT %s", quote_identifier(slotname));
+       appendStringInfo(&cmd, "DROP_REPLICATION_SLOT %s WAIT", quote_identifier(slotname));
 
        wrconn = walrcv_connect(conninfo, true, subname, &err);
        if (wrconn == NULL)
index ec047c827cf0b261dc913b2213273730204e97ac..a012447fa2ab66508d5c5bc865cf3b456fa6903e 100644 (file)
@@ -72,6 +72,7 @@ static SQLCmd *make_sqlcmd(void);
 %token K_LABEL
 %token K_PROGRESS
 %token K_FAST
+%token K_WAIT
 %token K_NOWAIT
 %token K_MAX_RATE
 %token K_WAL
@@ -272,6 +273,15 @@ drop_replication_slot:
                                        DropReplicationSlotCmd *cmd;
                                        cmd = makeNode(DropReplicationSlotCmd);
                                        cmd->slotname = $2;
+                                       cmd->wait = false;
+                                       $$ = (Node *) cmd;
+                               }
+                       | K_DROP_REPLICATION_SLOT IDENT K_WAIT
+                               {
+                                       DropReplicationSlotCmd *cmd;
+                                       cmd = makeNode(DropReplicationSlotCmd);
+                                       cmd->slotname = $2;
+                                       cmd->wait = true;
                                        $$ = (Node *) cmd;
                                }
                        ;
index 52ae7b343fbfaad6e592aafbd42e4a9e1d8c374e..62bb5288c0196b32a157526e3f5bc3d3ea507099 100644 (file)
@@ -103,6 +103,7 @@ TEMPORARY                   { return K_TEMPORARY; }
 EXPORT_SNAPSHOT                { return K_EXPORT_SNAPSHOT; }
 NOEXPORT_SNAPSHOT      { return K_NOEXPORT_SNAPSHOT; }
 USE_SNAPSHOT           { return K_USE_SNAPSHOT; }
+WAIT                           { return K_WAIT; }
 
 ","                            { return ','; }
 ";"                            { return ';'; }
index d4cbd83bde14ee181caf2ecef8f68fd214ea8cd2..ab776e85d2fd32605c5209c571ced43a90c1bf2b 100644 (file)
@@ -171,7 +171,7 @@ pg_drop_replication_slot(PG_FUNCTION_ARGS)
 
        CheckSlotRequirements();
 
-       ReplicationSlotDrop(NameStr(*name), false);
+       ReplicationSlotDrop(NameStr(*name), true);
 
        PG_RETURN_VOID();
 }
index 03e1cf44dee232569aa895bee7a6dbe3160bf9a4..db346e6edbdbcc6a95dd51ca1cb3b34849080e5e 100644 (file)
@@ -1028,7 +1028,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
 static void
 DropReplicationSlot(DropReplicationSlotCmd *cmd)
 {
-       ReplicationSlotDrop(cmd->slotname, false);
+       ReplicationSlotDrop(cmd->slotname, !cmd->wait);
        EndCommand("DROP_REPLICATION_SLOT", DestRemote);
 }
 
index dea61e90e9685097caeb3705a5341a4b8077b0d4..2053ffabe09c380c3f68e8f1817040d42d2c1539 100644 (file)
@@ -68,6 +68,7 @@ typedef struct DropReplicationSlotCmd
 {
        NodeTag         type;
        char       *slotname;
+       bool            wait;
 } DropReplicationSlotCmd;