public inbox for [email protected]  
help / color / mirror / Atom feed
From: Euler Taveira <[email protected]>
To: Michael Paquier <[email protected]>
To: Peter Eisentraut <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: change default default_toast_compression to lz4?
Date: Wed, 26 Nov 2025 15:59:37 -0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

On Wed, Nov 26, 2025, at 1:35 AM, Michael Paquier wrote:
> On Fri, Nov 21, 2025 at 12:11:38PM +0100, Peter Eisentraut wrote:
>> I suppose one issue is that lz4 support is not compiled-in by default, but
>> in practice most users will have it.  The default could be lz4 if lz4
>> support is built, otherwise pglz.  This would be similar to other parameters
>> where the default is the best one depending on the build configuration.
>
> +1.  That makes sense here to flip the default depending on what the
> code is built with, with lz4 if available, pglz otherwise.
>

Since we have an agreement that $SUBJECT is ok, I wrote a patch for it. It
selects the compression method based on USE_LZ4. It also adjusts the
postgresql.conf if required.


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/

Attachments:

  [text/x-patch] v1-0001-Change-default_toast_compression-to-lz4.patch (3.7K, ../[email protected]/2-v1-0001-Change-default_toast_compression-to-lz4.patch)
  download | inline diff:
From 89084e17df13823077bad2f6ad4c1cb0e095ccc4 Mon Sep 17 00:00:00 2001
From: Euler Taveira <[email protected]>
Date: Wed, 26 Nov 2025 12:40:43 -0300
Subject: [PATCH v1] 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.
---
 doc/src/sgml/config.sgml                      | 3 ++-
 src/backend/access/common/toast_compression.c | 2 +-
 src/backend/utils/misc/guc_parameters.dat     | 2 +-
 src/bin/initdb/initdb.c                       | 5 +++++
 src/include/access/toast_compression.h        | 9 +++++++++
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 737b90736bf..c063f013e2f 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -9910,7 +9910,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/src/backend/access/common/toast_compression.c b/src/backend/access/common/toast_compression.c
index 926f1e4008a..4bb29665eab 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 3b9d8349078..cbe9bf055b3 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/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 92fe2f531f7..92b120d8ab8 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1424,6 +1424,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 13c4612ceed..7526ea50c5a 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 struct varlena *pglz_compress_datum(const struct varlena *value);
-- 
2.39.5



view thread (13+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: change default default_toast_compression to lz4?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox