diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/transam/xlog.c | 30 | ||||
-rw-r--r-- | src/backend/replication/slotfuncs.c | 13 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 11 | ||||
-rw-r--r-- | src/backend/utils/misc/postgresql.conf.sample | 2 | ||||
-rw-r--r-- | src/bin/pg_rewind/t/RewindTest.pm | 4 | ||||
-rw-r--r-- | src/include/access/xlog.h | 4 | ||||
-rw-r--r-- | src/test/recovery/t/019_replslot_limit.pl | 10 |
7 files changed, 41 insertions, 33 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0a97b1d37fb..184c6672f3b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -88,7 +88,7 @@ extern uint32 bootstrap_data_checksum_version; /* User-settable parameters */ int max_wal_size_mb = 1024; /* 1 GB */ int min_wal_size_mb = 80; /* 80 MB */ -int wal_keep_segments = 0; +int wal_keep_size_mb = 0; int XLOGbuffers = -1; int XLogArchiveTimeout = 0; int XLogArchiveMode = ARCHIVE_MODE_OFF; @@ -9525,7 +9525,7 @@ GetWALAvailability(XLogRecPtr targetLSN) /* * Calculate the oldest segment currently reserved by all slots, - * considering wal_keep_segments and max_slot_wal_keep_size. Initialize + * considering wal_keep_size and max_slot_wal_keep_size. Initialize * oldestSlotSeg to the current segment. */ currpos = GetXLogWriteRecPtr(); @@ -9576,9 +9576,9 @@ GetWALAvailability(XLogRecPtr targetLSN) /* * Retreat *logSegNo to the last segment that we need to retain because of - * either wal_keep_segments or replication slots. + * either wal_keep_size or replication slots. * - * This is calculated by subtracting wal_keep_segments from the given xlog + * This is calculated by subtracting wal_keep_size from the given xlog * location, recptr and by making sure that that result is below the * requirement of replication slots. For the latter criterion we do consider * the effects of max_slot_wal_keep_size: reserve at most that much space back @@ -9616,14 +9616,20 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) } } - /* but, keep at least wal_keep_segments if that's set */ - if (wal_keep_segments > 0 && currSegNo - segno < wal_keep_segments) + /* but, keep at least wal_keep_size if that's set */ + if (wal_keep_size_mb > 0) { - /* avoid underflow, don't go below 1 */ - if (currSegNo <= wal_keep_segments) - segno = 1; - else - segno = currSegNo - wal_keep_segments; + uint64 keep_segs; + + keep_segs = ConvertToXSegs(wal_keep_size_mb, wal_segment_size); + if (currSegNo - segno < keep_segs) + { + /* avoid underflow, don't go below 1 */ + if (currSegNo <= keep_segs) + segno = 1; + else + segno = currSegNo - keep_segs; + } } /* don't delete WAL segments newer than the calculated segment */ @@ -11328,7 +11334,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) * If archiving is enabled, wait for all the required WAL files to be * archived before returning. If archiving isn't enabled, the required WAL * needs to be transported via streaming replication (hopefully with - * wal_keep_segments set high enough), or some more exotic mechanism like + * wal_keep_size set high enough), or some more exotic mechanism like * polling and copying files from pg_wal with script. We have no knowledge * of those mechanisms, so it's up to the user to ensure that he gets all * the required WAL. diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index 9fe147bf44e..f88694672fb 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -413,19 +413,20 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) else { XLogSegNo targetSeg; - XLogSegNo keepSegs; + uint64 slotKeepSegs; + uint64 keepSegs; XLogSegNo failSeg; XLogRecPtr failLSN; XLByteToSeg(slot_contents.data.restart_lsn, targetSeg, wal_segment_size); - /* determine how many segments slots can be kept by slots ... */ - keepSegs = XLogMBVarToSegs(max_slot_wal_keep_size_mb, wal_segment_size); - /* ... and override by wal_keep_segments as needed */ - keepSegs = Max(keepSegs, wal_keep_segments); + /* determine how many segments slots can be kept by slots */ + slotKeepSegs = XLogMBVarToSegs(max_slot_wal_keep_size_mb, wal_segment_size); + /* ditto for wal_keep_size */ + keepSegs = XLogMBVarToSegs(wal_keep_size_mb, wal_segment_size); /* if currpos reaches failLSN, we lose our segment */ - failSeg = targetSeg + keepSegs + 1; + failSeg = targetSeg + Max(slotKeepSegs, keepSegs) + 1; XLogSegNoOffsetToRecPtr(failSeg, 0, wal_segment_size, failLSN); values[i++] = Int64GetDatum(failLSN - currlsn); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 99a3e4f6f65..6f603cbbe8c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2636,12 +2636,13 @@ static struct config_int ConfigureNamesInt[] = }, { - {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING, - gettext_noop("Sets the number of WAL files held for standby servers."), - NULL + {"wal_keep_size", PGC_SIGHUP, REPLICATION_SENDING, + gettext_noop("Sets the size of WAL files held for standby servers."), + NULL, + GUC_UNIT_MB }, - &wal_keep_segments, - 0, 0, INT_MAX, + &wal_keep_size_mb, + 0, 0, MAX_KILOBYTES, NULL, NULL, NULL }, diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 29e01521966..5a0b8e98217 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -290,7 +290,7 @@ #max_wal_senders = 10 # max number of walsender processes # (change requires restart) -#wal_keep_segments = 0 # in logfile segments; 0 disables +#wal_keep_size = 0 # in megabytes; 0 disables #max_slot_wal_keep_size = -1 # in megabytes; -1 disables #wal_sender_timeout = 60s # in milliseconds; 0 disables diff --git a/src/bin/pg_rewind/t/RewindTest.pm b/src/bin/pg_rewind/t/RewindTest.pm index 7516af7a01a..41ed7d4b3be 100644 --- a/src/bin/pg_rewind/t/RewindTest.pm +++ b/src/bin/pg_rewind/t/RewindTest.pm @@ -135,11 +135,11 @@ sub setup_cluster extra => $extra, auth_extra => [ '--create-role', 'rewind_user' ]); - # Set wal_keep_segments to prevent WAL segment recycling after enforced + # Set wal_keep_size to prevent WAL segment recycling after enforced # checkpoints in the tests. $node_primary->append_conf( 'postgresql.conf', qq( -wal_keep_segments = 20 +wal_keep_size = 320MB )); return; } diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index d8391aa3783..219a7299e1f 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -107,7 +107,7 @@ extern bool reachedConsistency; extern int wal_segment_size; extern int min_wal_size_mb; extern int max_wal_size_mb; -extern int wal_keep_segments; +extern int wal_keep_size_mb; extern int max_slot_wal_keep_size_mb; extern int XLOGbuffers; extern int XLogArchiveTimeout; @@ -273,7 +273,7 @@ typedef enum WALAvailability WALAVAIL_INVALID_LSN, /* parameter error */ WALAVAIL_RESERVED, /* WAL segment is within max_wal_size */ WALAVAIL_EXTENDED, /* WAL segment is reserved by a slot or - * wal_keep_segments */ + * wal_keep_size */ WALAVAIL_UNRESERVED, /* no longer reserved, but not removed yet */ WALAVAIL_REMOVED /* WAL segment has been removed */ } WALAvailability; diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index 1fced12fca5..20f4a1bbc3d 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -116,19 +116,19 @@ $start_lsn = $node_primary->lsn('write'); $node_primary->wait_for_catchup($node_standby, 'replay', $start_lsn); $node_standby->stop; -# wal_keep_segments overrides max_slot_wal_keep_size +# wal_keep_size overrides max_slot_wal_keep_size $result = $node_primary->safe_psql('postgres', - "ALTER SYSTEM SET wal_keep_segments to 8; SELECT pg_reload_conf();"); + "ALTER SYSTEM SET wal_keep_size to '8MB'; SELECT pg_reload_conf();"); # Advance WAL again then checkpoint, reducing remain by 6 MB. advance_wal($node_primary, 6); $result = $node_primary->safe_psql('postgres', "SELECT wal_status as remain FROM pg_replication_slots WHERE slot_name = 'rep1'" ); is($result, "extended", - 'check that wal_keep_segments overrides max_slot_wal_keep_size'); -# restore wal_keep_segments + 'check that wal_keep_size overrides max_slot_wal_keep_size'); +# restore wal_keep_size $result = $node_primary->safe_psql('postgres', - "ALTER SYSTEM SET wal_keep_segments to 0; SELECT pg_reload_conf();"); + "ALTER SYSTEM SET wal_keep_size to 0; SELECT pg_reload_conf();"); # The standby can reconnect to primary $node_standby->start; |