Skip to content

Commit 24f6c1b

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 e43fae1 commit 24f6c1b

File tree

5 files changed

+13
-47
lines changed

5 files changed

+13
-47
lines changed

src/backend/access/transam/xlog.c

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

2218-
/*
2219-
* GUC check_hook for max_slot_wal_keep_size
2220-
*
2221-
* We don't allow the value of max_slot_wal_keep_size other than -1 during the
2222-
* binary upgrade. See start_postmaster() in pg_upgrade for more details.
2223-
*/
2224-
bool
2225-
check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source)
2226-
{
2227-
if (IsBinaryUpgrade && *newval != -1)
2228-
{
2229-
GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.",
2230-
"max_slot_wal_keep_size");
2231-
return false;
2232-
}
2233-
2234-
return true;
2235-
}
2236-
22372218
/*
22382219
* At a checkpoint, how many WAL segments to recycle as preallocated future
22392220
* XLOG segments? Returns the highest segment that should be preallocated.
@@ -7992,17 +7973,19 @@ KeepLogSeg(XLogRecPtr recptr, XLogRecPtr slotsMinReqLSN, XLogSegNo *logSegNo)
79927973
XLByteToSeg(recptr, currSegNo, wal_segment_size);
79937974
segno = currSegNo;
79947975

7995-
/*
7996-
* Calculate how many segments are kept by slots first, adjusting for
7997-
* max_slot_wal_keep_size.
7998-
*/
7976+
/* Calculate how many segments are kept by slots. */
79997977
keep = slotsMinReqLSN;
80007978
if (keep != InvalidXLogRecPtr && keep < recptr)
80017979
{
80027980
XLByteToSeg(keep, segno, wal_segment_size);
80037981

8004-
/* Cap by max_slot_wal_keep_size ... */
8005-
if (max_slot_wal_keep_size_mb >= 0)
7982+
/*
7983+
* Account for max_slot_wal_keep_size to avoid keeping more than
7984+
* configured. However, don't do that during a binary upgrade: if
7985+
* slots were to be invalidated because of this, it would not be
7986+
* possible to preserve logical ones during the upgrade.
7987+
*/
7988+
if (max_slot_wal_keep_size_mb >= 0 && !IsBinaryUpgrade)
80067989
{
80077990
uint64 slot_keep_segs;
80087991

src/backend/replication/slot.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,14 +1671,6 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause,
16711671

16721672
SpinLockRelease(&s->mutex);
16731673

1674-
/*
1675-
* The logical replication slots shouldn't be invalidated as GUC
1676-
* max_slot_wal_keep_size is set to -1 during the binary upgrade. See
1677-
* check_old_cluster_for_valid_slots() where we ensure that no
1678-
* invalidated before the upgrade.
1679-
*/
1680-
Assert(!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade));
1681-
16821674
if (active_pid != 0)
16831675
{
16841676
/*
@@ -1805,6 +1797,10 @@ InvalidateObsoleteReplicationSlots(ReplicationSlotInvalidationCause cause,
18051797
if (!s->in_use)
18061798
continue;
18071799

1800+
/* Prevent invalidation of logical slots during binary upgrade. */
1801+
if (SlotIsLogical(s) && IsBinaryUpgrade)
1802+
continue;
1803+
18081804
if (InvalidatePossiblyObsoleteSlot(cause, s, oldestLSN, dboid,
18091805
snapshotConflictHorizon,
18101806
&invalidated))

src/backend/utils/misc/guc_tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ struct config_int ConfigureNamesInt[] =
29532953
},
29542954
&max_slot_wal_keep_size_mb,
29552955
-1, -1, MAX_KILOBYTES,
2956-
check_max_slot_wal_keep_size, NULL, NULL
2956+
NULL, NULL, NULL
29572957
},
29582958

29592959
{

src/bin/pg_upgrade/server.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +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-
255244
/*
256245
* Use -b to disable autovacuum and logical replication launcher
257246
* (effective in PG17 or later for the latter).

src/include/utils/guc_hooks.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ extern bool check_maintenance_io_concurrency(int *newval, void **extra,
8686
extern void assign_maintenance_io_concurrency(int newval, void *extra);
8787
extern bool check_max_connections(int *newval, void **extra, GucSource source);
8888
extern bool check_max_wal_senders(int *newval, void **extra, GucSource source);
89-
extern bool check_max_slot_wal_keep_size(int *newval, void **extra,
90-
GucSource source);
9189
extern void assign_max_wal_size(int newval, void *extra);
9290
extern bool check_max_worker_processes(int *newval, void **extra,
9391
GucSource source);

0 commit comments

Comments
 (0)