mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Fix the handling of two GUCs during upgrade.
Previously, the check_hook functions for max_slot_wal_keep_size and idle_replication_slot_timeout would incorrectly raise an ERROR for values set in postgresql.conf during upgrade, even though those values were not actively used in the upgrade process. To prevent logical slot invalidation during upgrade, we used to set special values for these GUCs. Now, instead of relying on those values, we directly prevent WAL removal and logical slot invalidation caused by max_slot_wal_keep_size and idle_replication_slot_timeout. Note: PostgreSQL 17 does not include the idle_replication_slot_timeout GUC, so related changes were not backported. BUG #18979 Reported-by: jorsol <jorsol@gmail.com> Author: Dilip Kumar <dilipbalaut@gmail.com> Reviewed by: vignesh C <vignesh21@gmail.com> Reviewed by: Alvaro Herrera <alvherre@alvh.no-ip.org> Backpatch-through: 17, where it was introduced Discussion: https://postgr.es/m/219561.1751826409@sss.pgh.pa.us Discussion: https://postgr.es/m/18979-a1b7fdbb7cd181c6@postgresql.org
This commit is contained in:
@@ -2346,25 +2346,6 @@ check_wal_segment_size(int *newval, void **extra, GucSource source)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* GUC check_hook for max_slot_wal_keep_size
|
||||
*
|
||||
* We don't allow the value of max_slot_wal_keep_size other than -1 during the
|
||||
* binary upgrade. See start_postmaster() in pg_upgrade for more details.
|
||||
*/
|
||||
bool
|
||||
check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
if (IsBinaryUpgrade && *newval != -1)
|
||||
{
|
||||
GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.",
|
||||
"max_slot_wal_keep_size");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* At a checkpoint, how many WAL segments to recycle as preallocated future
|
||||
* XLOG segments? Returns the highest segment that should be preallocated.
|
||||
@@ -8150,17 +8131,19 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
|
||||
XLByteToSeg(recptr, currSegNo, wal_segment_size);
|
||||
segno = currSegNo;
|
||||
|
||||
/*
|
||||
* Calculate how many segments are kept by slots first, adjusting for
|
||||
* max_slot_wal_keep_size.
|
||||
*/
|
||||
/* Calculate how many segments are kept by slots. */
|
||||
keep = XLogGetReplicationSlotMinimumLSN();
|
||||
if (keep != InvalidXLogRecPtr && keep < recptr)
|
||||
{
|
||||
XLByteToSeg(keep, segno, wal_segment_size);
|
||||
|
||||
/* Cap by max_slot_wal_keep_size ... */
|
||||
if (max_slot_wal_keep_size_mb >= 0)
|
||||
/*
|
||||
* Account for max_slot_wal_keep_size to avoid keeping more than
|
||||
* configured. However, don't do that during a binary upgrade: if
|
||||
* slots were to be invalidated because of this, it would not be
|
||||
* possible to preserve logical ones during the upgrade.
|
||||
*/
|
||||
if (max_slot_wal_keep_size_mb >= 0 && !IsBinaryUpgrade)
|
||||
{
|
||||
uint64 slot_keep_segs;
|
||||
|
||||
|
||||
@@ -1887,15 +1887,6 @@ InvalidatePossiblyObsoleteSlot(uint32 possible_causes,
|
||||
|
||||
SpinLockRelease(&s->mutex);
|
||||
|
||||
/*
|
||||
* The logical replication slots shouldn't be invalidated as GUC
|
||||
* max_slot_wal_keep_size is set to -1 and
|
||||
* idle_replication_slot_timeout is set to 0 during the binary
|
||||
* upgrade. See check_old_cluster_for_valid_slots() where we ensure
|
||||
* that no slot was invalidated before the upgrade.
|
||||
*/
|
||||
Assert(!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade));
|
||||
|
||||
/*
|
||||
* Calculate the idle time duration of the slot if slot is marked
|
||||
* invalidated with RS_INVAL_IDLE_TIMEOUT.
|
||||
@@ -2042,6 +2033,10 @@ restart:
|
||||
if (!s->in_use)
|
||||
continue;
|
||||
|
||||
/* Prevent invalidation of logical slots during binary upgrade */
|
||||
if (SlotIsLogical(s) && IsBinaryUpgrade)
|
||||
continue;
|
||||
|
||||
if (InvalidatePossiblyObsoleteSlot(possible_causes, s, oldestLSN, dboid,
|
||||
snapshotConflictHorizon,
|
||||
&invalidated))
|
||||
@@ -3054,22 +3049,3 @@ WaitForStandbyConfirmation(XLogRecPtr wait_for_lsn)
|
||||
|
||||
ConditionVariableCancelSleep();
|
||||
}
|
||||
|
||||
/*
|
||||
* GUC check_hook for idle_replication_slot_timeout
|
||||
*
|
||||
* The value of idle_replication_slot_timeout must be set to 0 during
|
||||
* a binary upgrade. See start_postmaster() in pg_upgrade for more details.
|
||||
*/
|
||||
bool
|
||||
check_idle_replication_slot_timeout(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
if (IsBinaryUpgrade && *newval != 0)
|
||||
{
|
||||
GUC_check_errdetail("\"%s\" must be set to 0 during binary upgrade mode.",
|
||||
"idle_replication_slot_timeout");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3081,7 +3081,7 @@ struct config_int ConfigureNamesInt[] =
|
||||
},
|
||||
&max_slot_wal_keep_size_mb,
|
||||
-1, -1, MAX_KILOBYTES,
|
||||
check_max_slot_wal_keep_size, NULL, NULL
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
@@ -3104,7 +3104,7 @@ struct config_int ConfigureNamesInt[] =
|
||||
},
|
||||
&idle_replication_slot_timeout_secs,
|
||||
0, 0, INT_MAX,
|
||||
check_idle_replication_slot_timeout, NULL, NULL
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user