Skip to content

Commit f36e577

Browse files
author
Amit Kapila
committed
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
1 parent a1973e5 commit f36e577

File tree

5 files changed

+14
-77
lines changed

5 files changed

+14
-77
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,25 +2346,6 @@ check_wal_segment_size(int *newval, void **extra, GucSource source)
23462346
return true;
23472347
}
23482348

2349-
/*
2350-
* GUC check_hook for max_slot_wal_keep_size
2351-
*
2352-
* We don't allow the value of max_slot_wal_keep_size other than -1 during the
2353-
* binary upgrade. See start_postmaster() in pg_upgrade for more details.
2354-
*/
2355-
bool
2356-
check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source)
2357-
{
2358-
if (IsBinaryUpgrade && *newval != -1)
2359-
{
2360-
GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.",
2361-
"max_slot_wal_keep_size");
2362-
return false;
2363-
}
2364-
2365-
return true;
2366-
}
2367-
23682349
/*
23692350
* At a checkpoint, how many WAL segments to recycle as preallocated future
23702351
* XLOG segments? Returns the highest segment that should be preallocated.
@@ -8151,17 +8132,19 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
81518132
XLByteToSeg(recptr, currSegNo, wal_segment_size);
81528133
segno = currSegNo;
81538134

8154-
/*
8155-
* Calculate how many segments are kept by slots first, adjusting for
8156-
* max_slot_wal_keep_size.
8157-
*/
8135+
/* Calculate how many segments are kept by slots. */
81588136
keep = XLogGetReplicationSlotMinimumLSN();
81598137
if (keep != InvalidXLogRecPtr && keep < recptr)
81608138
{
81618139
XLByteToSeg(keep, segno, wal_segment_size);
81628140

8163-
/* Cap by max_slot_wal_keep_size ... */
8164-
if (max_slot_wal_keep_size_mb >= 0)
8141+
/*
8142+
* Account for max_slot_wal_keep_size to avoid keeping more than
8143+
* configured. However, don't do that during a binary upgrade: if
8144+
* slots were to be invalidated because of this, it would not be
8145+
* possible to preserve logical ones during the upgrade.
8146+
*/
8147+
if (max_slot_wal_keep_size_mb >= 0 && !IsBinaryUpgrade)
81658148
{
81668149
uint64 slot_keep_segs;
81678150

src/backend/replication/slot.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,15 +1887,6 @@ InvalidatePossiblyObsoleteSlot(uint32 possible_causes,
18871887

18881888
SpinLockRelease(&s->mutex);
18891889

1890-
/*
1891-
* The logical replication slots shouldn't be invalidated as GUC
1892-
* max_slot_wal_keep_size is set to -1 and
1893-
* idle_replication_slot_timeout is set to 0 during the binary
1894-
* upgrade. See check_old_cluster_for_valid_slots() where we ensure
1895-
* that no slot was invalidated before the upgrade.
1896-
*/
1897-
Assert(!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade));
1898-
18991890
/*
19001891
* Calculate the idle time duration of the slot if slot is marked
19011892
* invalidated with RS_INVAL_IDLE_TIMEOUT.
@@ -2042,6 +2033,10 @@ InvalidateObsoleteReplicationSlots(uint32 possible_causes,
20422033
if (!s->in_use)
20432034
continue;
20442035

2036+
/* Prevent invalidation of logical slots during binary upgrade */
2037+
if (SlotIsLogical(s) && IsBinaryUpgrade)
2038+
continue;
2039+
20452040
if (InvalidatePossiblyObsoleteSlot(possible_causes, s, oldestLSN, dboid,
20462041
snapshotConflictHorizon,
20472042
&invalidated))
@@ -3054,22 +3049,3 @@ WaitForStandbyConfirmation(XLogRecPtr wait_for_lsn)
30543049

30553050
ConditionVariableCancelSleep();
30563051
}
3057-
3058-
/*
3059-
* GUC check_hook for idle_replication_slot_timeout
3060-
*
3061-
* The value of idle_replication_slot_timeout must be set to 0 during
3062-
* a binary upgrade. See start_postmaster() in pg_upgrade for more details.
3063-
*/
3064-
bool
3065-
check_idle_replication_slot_timeout(int *newval, void **extra, GucSource source)
3066-
{
3067-
if (IsBinaryUpgrade && *newval != 0)
3068-
{
3069-
GUC_check_errdetail("\"%s\" must be set to 0 during binary upgrade mode.",
3070-
"idle_replication_slot_timeout");
3071-
return false;
3072-
}
3073-
3074-
return true;
3075-
}

src/backend/utils/misc/guc_tables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,7 +3081,7 @@ struct config_int ConfigureNamesInt[] =
30813081
},
30823082
&max_slot_wal_keep_size_mb,
30833083
-1, -1, MAX_KILOBYTES,
3084-
check_max_slot_wal_keep_size, NULL, NULL
3084+
NULL, NULL, NULL
30853085
},
30863086

30873087
{
@@ -3104,7 +3104,7 @@ struct config_int ConfigureNamesInt[] =
31043104
},
31053105
&idle_replication_slot_timeout_secs,
31063106
0, 0, INT_MAX,
3107-
check_idle_replication_slot_timeout, NULL, NULL
3107+
NULL, NULL, NULL
31083108
},
31093109

31103110
{

src/bin/pg_upgrade/server.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,6 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
241241
if (cluster == &new_cluster)
242242
appendPQExpBufferStr(&pgoptions, " -c synchronous_commit=off -c fsync=off -c full_page_writes=off");
243243

244-
/*
245-
* Use max_slot_wal_keep_size as -1 to prevent the WAL removal by the
246-
* checkpointer process. If WALs required by logical replication slots
247-
* are removed, the slots are unusable. This setting prevents the
248-
* invalidation of slots during the upgrade. We set this option when
249-
* cluster is PG17 or later because logical replication slots can only be
250-
* migrated since then. Besides, max_slot_wal_keep_size is added in PG13.
251-
*/
252-
if (GET_MAJOR_VERSION(cluster->major_version) >= 1700)
253-
appendPQExpBufferStr(&pgoptions, " -c max_slot_wal_keep_size=-1");
254-
255-
/*
256-
* Use idle_replication_slot_timeout=0 to prevent slot invalidation due to
257-
* idle_timeout by checkpointer process during upgrade.
258-
*/
259-
if (GET_MAJOR_VERSION(cluster->major_version) >= 1800)
260-
appendPQExpBufferStr(&pgoptions, " -c idle_replication_slot_timeout=0");
261-
262244
/*
263245
* Use -b to disable autovacuum and logical replication launcher
264246
* (effective in PG17 or later for the latter).

src/include/utils/guc_hooks.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ extern const char *show_log_timezone(void);
8484
extern void assign_maintenance_io_concurrency(int newval, void *extra);
8585
extern void assign_io_max_combine_limit(int newval, void *extra);
8686
extern void assign_io_combine_limit(int newval, void *extra);
87-
extern bool check_max_slot_wal_keep_size(int *newval, void **extra,
88-
GucSource source);
8987
extern void assign_max_wal_size(int newval, void *extra);
9088
extern bool check_max_stack_depth(int *newval, void **extra, GucSource source);
9189
extern void assign_max_stack_depth(int newval, void *extra);
@@ -176,7 +174,5 @@ extern void assign_wal_sync_method(int new_wal_sync_method, void *extra);
176174
extern bool check_synchronized_standby_slots(char **newval, void **extra,
177175
GucSource source);
178176
extern void assign_synchronized_standby_slots(const char *newval, void *extra);
179-
extern bool check_idle_replication_slot_timeout(int *newval, void **extra,
180-
GucSource source);
181177

182178
#endif /* GUC_HOOKS_H */

0 commit comments

Comments
 (0)