diff --git a/configure b/configure index 4b8229e..04d59bc 100755 --- a/configure +++ b/configure @@ -3725,7 +3725,11 @@ case ${wal_segsize} in 16) ;; 32) ;; 64) ;; - *) as_fn_error $? "Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64." "$LINENO" 5 + 128) ;; + 256) ;; + 512) ;; + 1024) ;; + *) as_fn_error $? "Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64,128,256,512,1024." "$LINENO" 5 esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${wal_segsize}MB" >&5 $as_echo "${wal_segsize}MB" >&6; } diff --git a/configure.in b/configure.in index 6c74214..ed584f9 100644 --- a/configure.in +++ b/configure.in @@ -358,7 +358,11 @@ case ${wal_segsize} in 16) ;; 32) ;; 64) ;; - *) AC_MSG_ERROR([Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.]) + 128) ;; + 256) ;; + 512) ;; + 1024) ;; + *) AC_MSG_ERROR([Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64,128,256,512,1024.]) esac AC_MSG_RESULT([${wal_segsize}MB]) diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index 39774a0..26bfab1 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -1049,7 +1049,7 @@ su - postgres the size of each individual file in the WAL log. It may be useful to adjust this size to control the granularity of WAL log shipping. The default size is 16 megabytes. - The value must be a power of 2 between 1 and 64 (megabytes). + The value must be a power of 2 between 1 and 1024 (megabytes). Note that changing this value requires an initdb. diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 58790e0..aa56a6b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -86,8 +86,8 @@ extern uint32 bootstrap_data_checksum_version; /* User-settable parameters */ -int max_wal_size = 64; /* 1 GB */ -int min_wal_size = 5; /* 80 MB */ +int max_wal_size_mb = 1024; /* 1 GB */ +int min_wal_size_mb = 80; /* 80 MB */ int wal_keep_segments = 0; int XLOGbuffers = -1; int XLogArchiveTimeout = 0; @@ -738,6 +738,10 @@ static ControlFileData *ControlFile = NULL; #define UsableBytesInPage (XLOG_BLCKSZ - SizeOfXLogShortPHD) #define UsableBytesInSegment ((XLOG_SEG_SIZE / XLOG_BLCKSZ) * UsableBytesInPage - (SizeOfXLogLongPHD - SizeOfXLogShortPHD)) +/* Convert min_wal_size_mb and max wal_size_mb to equivalent segment count */ +#define ConvertToXSegs(x) \ + (x / (XLOG_SEG_SIZE / (1024 * 1024))) + /* * Private, possibly out-of-date copy of shared LogwrtResult. * See discussion above. @@ -2200,7 +2204,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic) } /* - * Calculate CheckPointSegments based on max_wal_size and + * Calculate CheckPointSegments based on max_wal_size_mb and * checkpoint_completion_target. */ static void @@ -2210,14 +2214,14 @@ CalculateCheckpointSegments(void) /*------- * Calculate the distance at which to trigger a checkpoint, to avoid - * exceeding max_wal_size. This is based on two assumptions: + * exceeding max_wal_size_mb. This is based on two assumptions: * * a) we keep WAL for two checkpoint cycles, back to the "prev" checkpoint. * b) during checkpoint, we consume checkpoint_completion_target * * number of segments consumed between checkpoints. *------- */ - target = (double) max_wal_size / (2.0 + CheckPointCompletionTarget); + target = (double) ConvertToXSegs(max_wal_size_mb) / (2.0 + CheckPointCompletionTarget); /* round down */ CheckPointSegments = (int) target; @@ -2229,7 +2233,7 @@ CalculateCheckpointSegments(void) void assign_max_wal_size(int newval, void *extra) { - max_wal_size = newval; + max_wal_size_mb = newval; CalculateCheckpointSegments(); } @@ -2253,12 +2257,12 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr) XLogSegNo recycleSegNo; /* - * Calculate the segment numbers that min_wal_size and max_wal_size + * Calculate the segment numbers that min_wal_size_mb and max_wal_size_mb * correspond to. Always recycle enough segments to meet the minimum, and * remove enough segments to stay below the maximum. */ - minSegNo = PriorRedoPtr / XLOG_SEG_SIZE + min_wal_size - 1; - maxSegNo = PriorRedoPtr / XLOG_SEG_SIZE + max_wal_size - 1; + minSegNo = PriorRedoPtr / XLOG_SEG_SIZE + ConvertToXSegs(min_wal_size_mb) - 1; + maxSegNo = PriorRedoPtr / XLOG_SEG_SIZE + ConvertToXSegs(max_wal_size_mb) - 1; /* * Between those limits, recycle enough segments to get us through to the diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 291bf76..28e395c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -728,6 +728,11 @@ static const unit_conversion memory_unit_conversion_table[] = {"MB", GUC_UNIT_KB, 1024}, {"kB", GUC_UNIT_KB, 1}, + {"TB", GUC_UNIT_MB, 1024 * 1024}, + {"GB", GUC_UNIT_MB, 1024}, + {"MB", GUC_UNIT_MB, 1}, + {"kB", GUC_UNIT_MB, -1024}, + {"TB", GUC_UNIT_BLOCKS, (1024 * 1024 * 1024) / (BLCKSZ / 1024)}, {"GB", GUC_UNIT_BLOCKS, (1024 * 1024) / (BLCKSZ / 1024)}, {"MB", GUC_UNIT_BLOCKS, 1024 / (BLCKSZ / 1024)}, @@ -738,11 +743,6 @@ static const unit_conversion memory_unit_conversion_table[] = {"MB", GUC_UNIT_XBLOCKS, 1024 / (XLOG_BLCKSZ / 1024)}, {"kB", GUC_UNIT_XBLOCKS, -(XLOG_BLCKSZ / 1024)}, - {"TB", GUC_UNIT_XSEGS, (1024 * 1024 * 1024) / (XLOG_SEG_SIZE / 1024)}, - {"GB", GUC_UNIT_XSEGS, (1024 * 1024) / (XLOG_SEG_SIZE / 1024)}, - {"MB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / (1024 * 1024))}, - {"kB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / 1024)}, - {""} /* end of table marker */ }; @@ -2235,10 +2235,10 @@ static struct config_int ConfigureNamesInt[] = {"min_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS, gettext_noop("Sets the minimum size to shrink the WAL to."), NULL, - GUC_UNIT_XSEGS + GUC_UNIT_MB }, - &min_wal_size, - 5, 2, INT_MAX, + &min_wal_size_mb, + 5 * (XLOG_SEG_SIZE/ (1024 * 1024)), 2, MAX_KILOBYTES, NULL, NULL, NULL }, @@ -2246,10 +2246,10 @@ static struct config_int ConfigureNamesInt[] = {"max_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS, gettext_noop("Sets the WAL size that triggers a checkpoint."), NULL, - GUC_UNIT_XSEGS + GUC_UNIT_MB }, - &max_wal_size, - 64, 2, INT_MAX, + &max_wal_size_mb, + 64 * (XLOG_SEG_SIZE/ (1024 * 1024)), 2, MAX_KILOBYTES, NULL, assign_max_wal_size, NULL }, @@ -8078,6 +8078,9 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) case GUC_UNIT_KB: values[2] = "kB"; break; + case GUC_UNIT_MB: + values[2] = "MB"; + break; case GUC_UNIT_BLOCKS: snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024); values[2] = pstrdup(buffer); @@ -8086,11 +8089,6 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024); values[2] = pstrdup(buffer); break; - case GUC_UNIT_XSEGS: - snprintf(buffer, sizeof(buffer), "%dMB", - XLOG_SEG_SIZE / (1024 * 1024)); - values[2] = pstrdup(buffer); - break; case GUC_UNIT_MS: values[2] = "ms"; break; diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index d4abf94..d23aab5 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -94,8 +94,8 @@ extern PGDLLIMPORT XLogRecPtr XactLastCommitEnd; extern bool reachedConsistency; /* these variables are GUC parameters related to XLOG */ -extern int min_wal_size; -extern int max_wal_size; +extern int min_wal_size_mb; +extern int max_wal_size_mb; extern int wal_keep_segments; extern int XLOGbuffers; extern int XLogArchiveTimeout; diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index 7dd3780..87d0741 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -218,7 +218,7 @@ typedef enum #define GUC_UNIT_KB 0x1000 /* value is in kilobytes */ #define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */ #define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */ -#define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */ +#define GUC_UNIT_MB 0x4000 /* value is in megabytes */ #define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */ #define GUC_UNIT_MS 0x10000 /* value is in milliseconds */