1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Raise a WARNING for max_slot_wal_keep_size in pg_createsubscriber.

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
This commit is contained in:
Amit Kapila
2025-02-18 12:15:43 +05:30
parent 53d3daa491
commit 217919dd09
2 changed files with 26 additions and 1 deletions

View 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>

View 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)