]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Raise a WARNING for max_slot_wal_keep_size in pg_createsubscriber.
authorAmit Kapila <akapila@postgresql.org>
Tue, 18 Feb 2025 06:45:43 +0000 (12:15 +0530)
committerAmit Kapila <akapila@postgresql.org>
Tue, 18 Feb 2025 06:45:43 +0000 (12:15 +0530)
During the pg_createsubscriber execution, it is possible that the required
WAL is removed from the primary/publisher node due to
'max_slot_wal_keep_size'.

This patch raises a WARNING during the '--dry-run' mode if the
'max_slot_wal_keep_size' is set to a non-default value on the
primary/publisher node.

Author: Shubham Khanna <khannashubham1197@gmail.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Discussion: https://postgr.es/m/CAHv8Rj+deqsQXOMa7Tck8CBQUbsua=+4AuMVQ2=MPM0f-ZHbjA@mail.gmail.com

doc/src/sgml/ref/pg_createsubscriber.sgml
src/bin/pg_basebackup/pg_createsubscriber.c

index 26b8e64a4e03b07eb67be526c003b9360147bc35..d56487fe2ca8158a6c3bf8bdb5e93b08dbe8da58 100644 (file)
@@ -377,6 +377,13 @@ PostgreSQL documentation
     server.  If the target server has a standby, replication will break and a
     fresh standby should be created.
    </para>
+
+   <para>
+    Replication failures can occur if required WAL files are missing. To prevent
+    this, the source server must set
+    <xref linkend="guc-max-slot-wal-keep-size"/> to <literal>-1</literal> to
+    ensure that required WAL files are not prematurely removed.
+   </para>
   </refsect2>
 
   <refsect2>
index 2d881d54f5b25c437f1976bce3d72704edc6b548..37fdf150b413cc9da79e57ad3d6200cc950b1c20 100644 (file)
@@ -849,6 +849,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
        int                     max_walsenders;
        int                     cur_walsenders;
        int                     max_prepared_transactions;
+       char       *max_slot_wal_keep_size;
 
        pg_log_info("checking settings on publisher");
 
@@ -872,6 +873,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
         * - wal_level = logical
         * - max_replication_slots >= current + number of dbs to be converted
         * - max_wal_senders >= current + number of dbs to be converted
+        * - max_slot_wal_keep_size = -1 (to prevent deletion of required WAL files)
         * -----------------------------------------------------------------------
         */
        res = PQexec(conn,
@@ -880,7 +882,8 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
                                 " (SELECT count(*) FROM pg_catalog.pg_replication_slots),"
                                 " pg_catalog.current_setting('max_wal_senders'),"
                                 " (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE backend_type = 'walsender'),"
-                                " pg_catalog.current_setting('max_prepared_transactions')");
+                                " pg_catalog.current_setting('max_prepared_transactions'),"
+                                " pg_catalog.current_setting('max_slot_wal_keep_size')");
 
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
@@ -895,6 +898,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
        max_walsenders = atoi(PQgetvalue(res, 0, 3));
        cur_walsenders = atoi(PQgetvalue(res, 0, 4));
        max_prepared_transactions = atoi(PQgetvalue(res, 0, 5));
+       max_slot_wal_keep_size = pg_strdup(PQgetvalue(res, 0, 6));
 
        PQclear(res);
 
@@ -905,6 +909,8 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
        pg_log_debug("publisher: current wal senders: %d", cur_walsenders);
        pg_log_debug("publisher: max_prepared_transactions: %d",
                                 max_prepared_transactions);
+       pg_log_debug("publisher: max_slot_wal_keep_size: %s",
+                                max_slot_wal_keep_size);
 
        disconnect_database(conn, false);
 
@@ -939,6 +945,18 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
                                                          "Prepared transactions will be replicated at COMMIT PREPARED.");
        }
 
+       /*
+        * Validate 'max_slot_wal_keep_size'. If this parameter is set to a
+        * non-default value, it may cause replication failures due to required
+        * WAL files being prematurely removed.
+        */
+       if (dry_run && (strcmp(max_slot_wal_keep_size, "-1") != 0))
+       {
+               pg_log_warning("required WAL could be removed from the publisher");
+               pg_log_warning_hint("Set the configuration parameter \"%s\" to -1 to ensure that required WAL files are not prematurely removed.",
+                                                       "max_slot_wal_keep_size");
+       }
+
        pg_free(wal_level);
 
        if (failed)