1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +03:00

Add support for LZ4 with compression of full-page writes in WAL

The logic is implemented so as there can be a choice in the compression
used when building a WAL record, and an extra per-record bit is used to
track down if a block is compressed with PGLZ, LZ4 or nothing.

wal_compression, the existing parameter, is changed to an enum with
support for the following backward-compatible values:
- "off", the default, to not use compression.
- "pglz" or "on", to compress FPWs with PGLZ.
- "lz4", the new mode, to compress FPWs with LZ4.

Benchmarking has showed that LZ4 outclasses easily PGLZ.  ZSTD would be
also an interesting choice, but going just with LZ4 for now makes the
patch minimalistic as toast compression is already able to use LZ4, so
there is no need to worry about any build-related needs for this
implementation.

Author: Andrey Borodin, Justin Pryzby
Reviewed-by: Dilip Kumar, Michael Paquier
Discussion: https://postgr.es/m/3037310D-ECB7-4BF1-AF20-01C10BB33A33@yandex-team.ru
This commit is contained in:
Michael Paquier
2021-06-29 11:17:55 +09:00
parent cc2c7d65fc
commit 4035cd5d4e
13 changed files with 191 additions and 52 deletions

View File

@@ -540,6 +540,22 @@ static struct config_enum_entry default_toast_compression_options[] = {
{NULL, 0, false}
};
static const struct config_enum_entry wal_compression_options[] = {
{"pglz", WAL_COMPRESSION_PGLZ, false},
#ifdef USE_LZ4
{"lz4", WAL_COMPRESSION_LZ4, false},
#endif
{"on", WAL_COMPRESSION_PGLZ, false},
{"off", WAL_COMPRESSION_NONE, false},
{"true", WAL_COMPRESSION_PGLZ, true},
{"false", WAL_COMPRESSION_NONE, true},
{"yes", WAL_COMPRESSION_PGLZ, true},
{"no", WAL_COMPRESSION_NONE, true},
{"1", WAL_COMPRESSION_PGLZ, true},
{"0", WAL_COMPRESSION_NONE, true},
{NULL, 0, false}
};
/*
* Options for enum values stored in other modules
*/
@@ -1304,16 +1320,6 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
{
{"wal_compression", PGC_SUSET, WAL_SETTINGS,
gettext_noop("Compresses full-page writes written in WAL file."),
NULL
},
&wal_compression,
false,
NULL, NULL, NULL
},
{
{"wal_init_zero", PGC_SUSET, WAL_SETTINGS,
gettext_noop("Writes zeroes to new WAL files before first use."),
@@ -4816,6 +4822,16 @@ static struct config_enum ConfigureNamesEnum[] =
NULL, NULL, NULL
},
{
{"wal_compression", PGC_SUSET, WAL_SETTINGS,
gettext_noop("Compresses full-page writes written in WAL file with specified method."),
NULL
},
&wal_compression,
WAL_COMPRESSION_NONE, wal_compression_options,
NULL, NULL, NULL
},
{
{"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
gettext_noop("Sets the level of information written to the WAL."),

View File

@@ -218,7 +218,8 @@
#full_page_writes = on # recover from partial page writes
#wal_log_hints = off # also do full page writes of non-critical updates
# (change requires restart)
#wal_compression = off # enable compression of full-page writes
#wal_compression = off # enables compression of full-page writes;
# off, pglz, lz4, or on
#wal_init_zero = on # zero-fill new WAL files
#wal_recycle = on # recycle WAL files
#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers