Skip to content

Commit 8bfb231

Browse files
author
Amit Kapila
committed
Prohibit max_slot_wal_keep_size to value other than -1 during upgrade.
We don't want existing slots in the old cluster to get invalidated during the upgrade. During an upgrade, we set this variable to -1 via the command line in an attempt to prevent such invalidations, but users have ways to override it. This patch ensures the value is not overridden by the user. Author: Kyotaro Horiguchi Reviewed-by: Peter Smith, Alvaro Herrera Discussion: http://postgr.es/m/[email protected]
1 parent 5ba1ac9 commit 8bfb231

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/backend/access/transam/xlog.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,25 @@ check_wal_segment_size(int *newval, void **extra, GucSource source)
20632063
return true;
20642064
}
20652065

2066+
/*
2067+
* GUC check_hook for max_slot_wal_keep_size
2068+
*
2069+
* We don't allow the value of max_slot_wal_keep_size other than -1 during the
2070+
* binary upgrade. See start_postmaster() in pg_upgrade for more details.
2071+
*/
2072+
bool
2073+
check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source)
2074+
{
2075+
if (IsBinaryUpgrade && *newval != -1)
2076+
{
2077+
GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.",
2078+
"max_slot_wal_keep_size");
2079+
return false;
2080+
}
2081+
2082+
return true;
2083+
}
2084+
20662085
/*
20672086
* At a checkpoint, how many WAL segments to recycle as preallocated future
20682087
* XLOG segments? Returns the highest segment that should be preallocated.

src/backend/replication/slot.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,18 +1424,12 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause,
14241424
SpinLockRelease(&s->mutex);
14251425

14261426
/*
1427-
* The logical replication slots shouldn't be invalidated as
1428-
* max_slot_wal_keep_size GUC is set to -1 during the upgrade.
1429-
*
1430-
* The following is just a sanity check.
1427+
* The logical replication slots shouldn't be invalidated as GUC
1428+
* max_slot_wal_keep_size is set to -1 during the binary upgrade. See
1429+
* check_old_cluster_for_valid_slots() where we ensure that no
1430+
* invalidated before the upgrade.
14311431
*/
1432-
if (*invalidated && SlotIsLogical(s) && IsBinaryUpgrade)
1433-
{
1434-
ereport(ERROR,
1435-
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1436-
errmsg("replication slots must not be invalidated during the upgrade"),
1437-
errhint("\"max_slot_wal_keep_size\" must be set to -1 during the upgrade"));
1438-
}
1432+
Assert(!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade));
14391433

14401434
if (active_pid != 0)
14411435
{

src/backend/utils/misc/guc_tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ struct config_int ConfigureNamesInt[] =
28452845
},
28462846
&max_slot_wal_keep_size_mb,
28472847
-1, -1, MAX_KILOBYTES,
2848-
NULL, NULL, NULL
2848+
check_max_slot_wal_keep_size, NULL, NULL
28492849
},
28502850

28512851
{

src/include/utils/guc_hooks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ extern bool check_maintenance_io_concurrency(int *newval, void **extra,
8484
extern void assign_maintenance_io_concurrency(int newval, void *extra);
8585
extern bool check_max_connections(int *newval, void **extra, GucSource source);
8686
extern bool check_max_wal_senders(int *newval, void **extra, GucSource source);
87+
extern bool check_max_slot_wal_keep_size(int *newval, void **extra,
88+
GucSource source);
8789
extern void assign_max_wal_size(int newval, void *extra);
8890
extern bool check_max_worker_processes(int *newval, void **extra,
8991
GucSource source);

0 commit comments

Comments
 (0)