Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d973363

Browse files
KhannaShubham1197Commitfest Bot
authored and
Commitfest Bot
committed
Validate-max_slot_wal_keep_size-in-pg_createsubscriber
This patch introduces validation for the 'max_slot_wal_keep_size' GUC in the 'pg_createsubscriber' utility. The utility now checks that the publisher's 'max_slot_wal_keep_size' is set to '-1' during subscription creation. This ensures proper functioning of logical replication slots. The 'pg_createsubscriber' utility is updated to fetch and validate the 'max_slot_wal_keep_size' setting from the publisher. A warning is raised during the '--dry-run' mode if the configuration is set to a non-default value. This patch logs a warning if 'max_slot_wal_keep_size' is not set to '-1', highlighting a potential risk of required WAL files being deleted on the publisher, which could disrupt logical replication. A test case has been added to validate correct warning reporting when 'max_slot_wal_keep_size' is misconfigured.
1 parent fc069a3 commit d973363

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

doc/src/sgml/ref/pg_createsubscriber.sgml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ PostgreSQL documentation
377377
server. If the target server has a standby, replication will break and a
378378
fresh standby should be created.
379379
</para>
380+
381+
<para>
382+
Replication failures can occur if required WAL files are missing. To prevent
383+
this, the source server must set
384+
<xref linkend="guc-max-slot-wal-keep-size"/> to <literal>-1</literal> to
385+
ensure that required WAL files are not prematurely removed.
386+
</para>
380387
</refsect2>
381388

382389
<refsect2>

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
849849
int max_walsenders;
850850
int cur_walsenders;
851851
int max_prepared_transactions;
852+
char *max_slot_wal_keep_size;
852853

853854
pg_log_info("checking settings on publisher");
854855

@@ -872,6 +873,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
872873
* - wal_level = logical
873874
* - max_replication_slots >= current + number of dbs to be converted
874875
* - max_wal_senders >= current + number of dbs to be converted
876+
* - max_slot_wal_keep_size = -1 (to prevent deletion of required WAL files)
875877
* -----------------------------------------------------------------------
876878
*/
877879
res = PQexec(conn,
@@ -880,7 +882,8 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
880882
" (SELECT count(*) FROM pg_catalog.pg_replication_slots),"
881883
" pg_catalog.current_setting('max_wal_senders'),"
882884
" (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE backend_type = 'walsender'),"
883-
" pg_catalog.current_setting('max_prepared_transactions')");
885+
" pg_catalog.current_setting('max_prepared_transactions'),"
886+
" pg_catalog.current_setting('max_slot_wal_keep_size')");
884887

885888
if (PQresultStatus(res) != PGRES_TUPLES_OK)
886889
{
@@ -895,6 +898,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
895898
max_walsenders = atoi(PQgetvalue(res, 0, 3));
896899
cur_walsenders = atoi(PQgetvalue(res, 0, 4));
897900
max_prepared_transactions = atoi(PQgetvalue(res, 0, 5));
901+
max_slot_wal_keep_size = pg_strdup(PQgetvalue(res, 0, 6));
898902

899903
PQclear(res);
900904

@@ -905,6 +909,8 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
905909
pg_log_debug("publisher: current wal senders: %d", cur_walsenders);
906910
pg_log_debug("publisher: max_prepared_transactions: %d",
907911
max_prepared_transactions);
912+
pg_log_debug("publisher: max_slot_wal_keep_size: %s",
913+
max_slot_wal_keep_size);
908914

909915
disconnect_database(conn, false);
910916

@@ -939,6 +945,18 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
939945
"Prepared transactions will be replicated at COMMIT PREPARED.");
940946
}
941947

948+
/*
949+
* Validate 'max_slot_wal_keep_size'. If this parameter is set to a
950+
* non-default value, it may cause replication failures due to required
951+
* WAL files being prematurely removed.
952+
*/
953+
if (dry_run && (strcmp(max_slot_wal_keep_size, "-1") != 0))
954+
{
955+
pg_log_warning("publisher requires WAL size must not be restricted");
956+
pg_log_warning_hint("Set the configuration parameter \"%s\" to -1 to ensure that required WAL files are not prematurely removed.",
957+
"max_slot_wal_keep_size");
958+
}
959+
942960
pg_free(wal_level);
943961

944962
if (failed)

0 commit comments

Comments
 (0)