On Thu, Dec 4, 2025, at 11:23 PM, Michael Paquier wrote:
>
> So this had better be adjusted in one go, in the shape of a tweak in
> mingw_cross_warning_script with the addition of a --without-lz4, same
> way as for ICU.
>
Done.

> Hmm.  It seems to me that we should just set not_found_dep if lz4
> cannot be found, leaving meson_options.txt as it is currently, no?
>
Done.

Changes from last version:

- adjust CI
- set not_found_dep instead of warning message
- remove quotes from default_toast_compression value

It is aligned with ICU and readline behavior.


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/
From 7dbe34634b9e49e4c9ec46a4114bd805865f1206 Mon Sep 17 00:00:00 2001
From: Euler Taveira <[email protected]>
Date: Wed, 26 Nov 2025 12:40:43 -0300
Subject: [PATCH v3] Change default_toast_compression to lz4

The default value for default_toast_compression was pglz. The main
reason is that this option is always available. However, it is known
that pglz uses more CPU than lz4. The default value will be lz4 if lz4
support is built, otherwise, pglz.

The autoconf behavior is to provide an error if lz4 dependency is not
found. You should inform --witthout-lz4 if lz4 is not available. The
meson behavior is to try to detect lz4, if not found, defaults to pglz.
It acts like ICU or readline that you have to opt out if you don't want
lz4 support.

While at it, remove quotes from default_toast_compression. We usually do
not use quotes for enum.
---
 .cirrus.tasks.yml                             |  1 +
 configure.ac                                  |  2 +-
 doc/src/sgml/config.sgml                      |  3 ++-
 doc/src/sgml/installation.sgml                | 12 ++++++++++++
 meson.build                                   |  2 ++
 src/backend/access/common/toast_compression.c |  2 +-
 src/backend/utils/misc/guc_parameters.dat     |  2 +-
 src/backend/utils/misc/postgresql.conf.sample |  2 +-
 src/bin/initdb/initdb.c                       |  5 +++++
 src/include/access/toast_compression.h        |  9 +++++++++
 10 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 2a821593ce5..1ad8a487632 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -983,6 +983,7 @@ task:
         --host=x86_64-w64-mingw32ucrt \
         --enable-cassert \
         --without-icu \
+        --without-lz4 \
         CC="ccache x86_64-w64-mingw32ucrt-gcc" \
         CXX="ccache x86_64-w64-mingw32ucrt-g++"
       make -s -j${BUILD_JOBS} clean
diff --git a/configure.ac b/configure.ac
index 455ba31f1d1..6b1e3e9de4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1173,7 +1173,7 @@ AC_SUBST(with_zlib)
 # LZ4
 #
 AC_MSG_CHECKING([whether to build with LZ4 support])
-PGAC_ARG_BOOL(with, lz4, no, [build with LZ4 support],
+PGAC_ARG_BOOL(with, lz4, yes, [build without LZ4 support],
               [AC_DEFINE([USE_LZ4], 1, [Define to 1 to build with LZ4 support. (--with-lz4)])])
 AC_MSG_RESULT([$with_lz4])
 AC_SUBST(with_lz4)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index faf0bdb62aa..381f02f86af 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -10022,7 +10022,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>
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index c903ccff988..4dcfc206a5d 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1315,6 +1315,18 @@ build-postgresql:
        </listitem>
       </varlistentry>
 
+      <varlistentry id="configure-option-without-lz4">
+       <term><option>--without-lz4</option></term>
+       <listitem>
+        <para>
+         <indexterm>
+          <primary>lz4</primary>
+         </indexterm>
+         Prevents use of the <application>LZ4</application> library.
+        </para>
+       </listitem>
+      </varlistentry>
+
      </variablelist>
 
    </sect3>
diff --git a/meson.build b/meson.build
index 055e96315d0..13ef9c18477 100644
--- a/meson.build
+++ b/meson.build
@@ -1133,6 +1133,8 @@ if not lz4opt.disabled()
   if lz4.found()
     cdata.set('USE_LZ4', 1)
     cdata.set('HAVE_LIBLZ4', 1)
+  else
+    lz4 = not_found_dep
   endif
 
 else
diff --git a/src/backend/access/common/toast_compression.c b/src/backend/access/common/toast_compression.c
index 4d00537049e..5a5d579494a 100644
--- a/src/backend/access/common/toast_compression.c
+++ b/src/backend/access/common/toast_compression.c
@@ -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, \
diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat
index 271c033952e..5522dcf3b88 100644
--- a/src/backend/utils/misc/guc_parameters.dat
+++ b/src/backend/utils/misc/guc_parameters.dat
@@ -735,7 +735,7 @@
 { 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',
 },
 
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index f938cc65a3a..e686d88afc4 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -779,7 +779,7 @@
 #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
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index a3980e5535f..66813c090d2 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -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.
 	 */
diff --git a/src/include/access/toast_compression.h b/src/include/access/toast_compression.h
index 5f3ffa9ab2d..ab4bdfd0384 100644
--- a/src/include/access/toast_compression.h
+++ b/src/include/access/toast_compression.h
@@ -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);
-- 
2.39.5

Reply via email to