The default value for default_toast_compression was "pglz". The main
reason for this choice is that this option is always available, pglz
code being embedded in Postgres. However, it is known that LZ4 is more
efficient than pglz: less CPU required, more compression on average. As
of this commit, the default value of default_toast_compression becomes
"lz4", if available. By switching to LZ4 as the default, users should
see natural speedups on TOAST data reads and/or writes.
Support for LZ4 in TOAST compression was added in Postgres v14, or 5
releases ago. This should be long enough to consider this feature as
stable.
While at it, quotes are removed from default_toast_compression in
postgresql.conf.sample. Quotes are not required in this case. The
in-place value replacement done by initdb if the build supports LZ4
would not use them in the postgresql.conf file added to a
freshly-initialized cluster.
Note that this is a version lighter than
7c1849311e49, that included a
replacement of --with-lz4 by --without-lz4 in configure builds, forcing
a requirement for LZ4 in all environments. The buildfarm did not like
it, at all. This commit switches default_toast_compression to lz4 as
default only when --with-lz4 is defined, which should keep the buildfarm
at bay while still allowing users to benefit from LZ4 compression in
TOAST as long as the code is compiled with it.
Author: Euler Taveira <euler@eulerto.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://posgr.es/m/
435df33a-129e-4f0c-a803-
f3935c5a5ecb@eisentraut.org
The supported compression methods are <literal>pglz</literal> and
(if <productname>PostgreSQL</productname> was compiled with
<option>--with-lz4</option>) <literal>lz4</literal>.
- The default is <literal>pglz</literal>.
+ The default is <literal>lz4</literal> (if available); otherwise,
+ <literal>pglz</literal>.
</para>
</listitem>
</varlistentry>
#include "varatt.h"
/* GUC */
-int default_toast_compression = TOAST_PGLZ_COMPRESSION;
+int default_toast_compression = DEFAULT_TOAST_COMPRESSION;
#define NO_COMPRESSION_SUPPORT(method) \
ereport(ERROR, \
{ name => 'default_toast_compression', type => 'enum', context => 'PGC_USERSET', group => 'CLIENT_CONN_STATEMENT',
short_desc => 'Sets the default compression method for compressible values.',
variable => 'default_toast_compression',
- boot_val => 'TOAST_PGLZ_COMPRESSION',
+ boot_val => 'DEFAULT_TOAST_COMPRESSION',
options => 'default_toast_compression_options',
},
#row_security = on
#default_table_access_method = 'heap'
#default_tablespace = '' # a tablespace name, '' uses the default
-#default_toast_compression = 'pglz' # 'pglz' or 'lz4'
+#default_toast_compression = pglz # pglz or lz4
#temp_tablespaces = '' # a list of tablespace names, '' uses
# only default tablespace
#check_function_bodies = on
"0640", false);
}
+#if USE_LZ4
+ conflines = replace_guc_value(conflines, "default_toast_compression",
+ "lz4", true);
+#endif
+
/*
* Now replace anything that's overridden via -c switches.
*/
#define CompressionMethodIsValid(cm) ((cm) != InvalidCompressionMethod)
+/*
+ * Choose an appropriate default toast compression method. If lz4 is
+ * compiled-in, use it, otherwise use pglz.
+ */
+#ifdef USE_LZ4
+#define DEFAULT_TOAST_COMPRESSION TOAST_LZ4_COMPRESSION
+#else
+#define DEFAULT_TOAST_COMPRESSION TOAST_PGLZ_COMPRESSION
+#endif
/* pglz compression/decompression routines */
extern varlena *pglz_compress_datum(const varlena *value);