mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Replace checkpoint_segments with min_wal_size and max_wal_size.
Instead of having a single knob (checkpoint_segments) that both triggers checkpoints, and determines how many checkpoints to recycle, they are now separate concerns. There is still an internal variable called CheckpointSegments, which triggers checkpoints. But it no longer determines how many segments to recycle at a checkpoint. That is now auto-tuned by keeping a moving average of the distance between checkpoints (in bytes), and trying to keep that many segments in reserve. The advantage of this is that you can set max_wal_size very high, but the system won't actually consume that much space if there isn't any need for it. The min_wal_size sets a floor for that; you can effectively disable the auto-tuning behavior by setting min_wal_size equal to max_wal_size. The max_wal_size setting is now the actual target size of WAL at which a new checkpoint is triggered, instead of the distance between checkpoints. Previously, you could calculate the actual WAL usage with the formula "(2 + checkpoint_completion_target) * checkpoint_segments + 1". With this patch, you set the desired WAL usage with max_wal_size, and the system calculates the appropriate CheckpointSegments with the reverse of that formula. That's a lot more intuitive for administrators to set. Reviewed by Amit Kapila and Venkata Balaji N.
This commit is contained in:
@ -685,6 +685,9 @@ typedef struct
|
||||
#if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
|
||||
#error XLOG_BLCKSZ must be between 1KB and 1MB
|
||||
#endif
|
||||
#if XLOG_SEG_SIZE < (1024*1024) || XLOG_BLCKSZ > (1024*1024*1024)
|
||||
#error XLOG_SEG_SIZE must be between 1MB and 1GB
|
||||
#endif
|
||||
|
||||
static const char *memory_units_hint =
|
||||
gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
|
||||
@ -706,6 +709,11 @@ 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 */
|
||||
};
|
||||
|
||||
@ -2146,15 +2154,27 @@ static struct config_int ConfigureNamesInt[] =
|
||||
},
|
||||
|
||||
{
|
||||
{"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
|
||||
gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
|
||||
NULL
|
||||
{"min_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
|
||||
gettext_noop("Sets the minimum size to shrink the WAL to."),
|
||||
NULL,
|
||||
GUC_UNIT_XSEGS
|
||||
},
|
||||
&CheckPointSegments,
|
||||
3, 1, INT_MAX,
|
||||
&min_wal_size,
|
||||
5, 2, INT_MAX,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"max_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
|
||||
gettext_noop("Sets the WAL size that triggers a checkpoint."),
|
||||
NULL,
|
||||
GUC_UNIT_XSEGS
|
||||
},
|
||||
&max_wal_size,
|
||||
8, 2, INT_MAX,
|
||||
NULL, assign_max_wal_size, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
|
||||
gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
|
||||
|
Reference in New Issue
Block a user