]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Change default value of default_toast_compression to "lz4", take two
authorMichael Paquier <michael@paquier.xyz>
Thu, 5 Mar 2026 00:24:35 +0000 (09:24 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 5 Mar 2026 00:24:35 +0000 (09:24 +0900)
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

doc/src/sgml/config.sgml
src/backend/access/common/toast_compression.c
src/backend/utils/misc/guc_parameters.dat
src/backend/utils/misc/postgresql.conf.sample
src/bin/initdb/initdb.c
src/include/access/toast_compression.h

index f670e2d4c31d2dd2a40e04c9c82c9b1721493544..cb7afca90798baa068b481f20cd964861aa3eebd 100644 (file)
@@ -10020,7 +10020,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
         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>
index 4d00537049ec1c77d4a09a199bc8f5c863b5af95..5a5d579494a2311065a4877f9d8eaff18d40ec0d 100644 (file)
@@ -23,7 +23,7 @@
 #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, \
index 9507778415da1a746c0e4a2e1e7038e8b4c6584b..5ee84a639d828b846fff0cd9c68938058bb261ae 100644 (file)
 { 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',
 },
 
index f938cc65a3aa96915187c5790bad11a8bc8ac106..e686d88afc427982ef40bd491f024290bcc1906e 100644 (file)
 #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
index 53ec1544ff3675b337ad14b0f96591582a83fdc6..6387c66289e2640a8e87e46a9d32c5c58f1453ab 100644 (file)
@@ -1426,6 +1426,11 @@ setup_config(void)
                                                                          "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.
         */
index 5f3ffa9ab2d46eb7e7383bb9569f336ae42d33ff..3265f10b734f46be1bafdc5bdbaa24a1bc92bcbe 100644 (file)
@@ -52,6 +52,15 @@ typedef enum ToastCompressionId
 
 #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);