Clean-ups for 776621a5e4 and 7329240437.
authorAmit Kapila <akapila@postgresql.org>
Wed, 7 Feb 2024 04:34:04 +0000 (10:04 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 7 Feb 2024 04:34:04 +0000 (10:04 +0530)
Following are a few clean-ups related to failover option support in slots:
1. Improve the documentation in create_subscription.sgml.
2. Remove the spurious blank line in subscriptioncmds.c.
3. Remove the NOTICE for alter_replication_slot in subscriptioncmds.c as
we would sometimes print it even when nothing has changed. One can find
the change by enabling log_replication_commands on the publisher.
4. Optimize ReplicationSlotAlter() function to prevent disk flushing when
the slot's data remains unchanged.

Author: Hou Zhijie
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com
Discussion: https://postgr.es/m/OS0PR01MB57164904651FB588A518E98894472@OS0PR01MB5716.jpnprd01.prod.outlook.com

doc/src/sgml/ref/create_subscription.sgml
doc/src/sgml/ref/pg_dump.sgml
src/backend/commands/subscriptioncmds.c
src/backend/replication/slot.c

index ee89ffb1d1247051ee4d90fe9e78ed0445553692..15794731bbb7c36cca6ad342dcd25b0400e5536e 100644 (file)
@@ -117,9 +117,8 @@ CREATE SUBSCRIPTION <replaceable class="parameter">subscription_name</replaceabl
           command should connect to the publisher at all.  The default
           is <literal>true</literal>.  Setting this to
           <literal>false</literal> will force the values of
-          <literal>create_slot</literal>, <literal>enabled</literal>,
-          <literal>copy_data</literal>, and <literal>failover</literal>
-          to <literal>false</literal>.
+          <literal>create_slot</literal>, <literal>enabled</literal> and
+          <literal>copy_data</literal> to <literal>false</literal>.
           (You cannot combine setting <literal>connect</literal>
           to <literal>false</literal> with
           setting <literal>create_slot</literal>, <literal>enabled</literal>,
index f8ae4220e1dec2d674f97122a36519e875eb0da3..0caf56e0e04cac50dbd18863ac529d8b1b86507a 100644 (file)
@@ -1591,9 +1591,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
    information might have to be changed.  If the subscription needs to
    be enabled for
    <link linkend="sql-createsubscription-params-with-failover"><literal>failover</literal></link>,
-   then same needs to be done by executing
-   <link linkend="sql-altersubscription-params-set">
-   <literal>ALTER SUBSCRIPTION ... SET (failover = true)</literal></link>
+   execute <link linkend="sql-altersubscription-params-set"><literal>ALTER SUBSCRIPTION ... SET (failover = true)</literal></link>
    after the slot has been created.  It might also be appropriate to
    truncate the target tables before initiating a new full table copy.  If users
    intend to copy initial data during refresh they must create the slot with
index a400ba0e40cc5f10f4eca46f6b5c2bc4800bb499..a05d69922d9278f7dceb9be96eb57056ffe2a7fd 100644 (file)
@@ -73,7 +73,6 @@
 #define SUBOPT_LSN                 0x00004000
 #define SUBOPT_ORIGIN              0x00008000
 
-
 /* check if the 'val' has 'bits' set */
 #define IsSet(val, bits)  (((val) & (bits)) == (bits))
 
@@ -852,9 +851,6 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt,
                     (opts.failover || walrcv_server_version(wrconn) >= 170000))
            {
                walrcv_alter_slot(wrconn, opts.slot_name, opts.failover);
-               ereport(NOTICE,
-                       (errmsg("changed the failover state of replication slot \"%s\" on publisher to %s",
-                               opts.slot_name, opts.failover ? "true" : "false")));
            }
        }
        PG_FINALLY();
@@ -1547,10 +1543,6 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
        PG_TRY();
        {
            walrcv_alter_slot(wrconn, sub->slotname, opts.failover);
-
-           ereport(NOTICE,
-                   (errmsg("changed the failover state of replication slot \"%s\" on publisher to %s",
-                           sub->slotname, opts.failover ? "true" : "false")));
        }
        PG_FINALLY();
        {
index 110cb59783f039b0fde4ec6517759e48bd719511..fd4e96c9d69e4ceeda6bba93d2ad0c5ad0abdc13 100644 (file)
@@ -696,12 +696,16 @@ ReplicationSlotAlter(const char *name, bool failover)
                errmsg("cannot use %s with a physical replication slot",
                       "ALTER_REPLICATION_SLOT"));
 
-   SpinLockAcquire(&MyReplicationSlot->mutex);
-   MyReplicationSlot->data.failover = failover;
-   SpinLockRelease(&MyReplicationSlot->mutex);
+   if (MyReplicationSlot->data.failover != failover)
+   {
+       SpinLockAcquire(&MyReplicationSlot->mutex);
+       MyReplicationSlot->data.failover = failover;
+       SpinLockRelease(&MyReplicationSlot->mutex);
+
+       ReplicationSlotMarkDirty();
+       ReplicationSlotSave();
+   }
 
-   ReplicationSlotMarkDirty();
-   ReplicationSlotSave();
    ReplicationSlotRelease();
 }