Hi,
The documentation states that "WAL summarization cannot be enabled when wal_level is
set to minimal." Therefore, at startup, the postmaster checks these settings and
exits with an error if they are not configured properly.
However, I found that summarize_wal can still be enabled while the server is
running with wal_level=minimal. Please see the following example to cause this
situation. I think this is a bug.
=# SHOW wal_level;
wal_level
-----------
minimal
(1 row)
=# SELECT * FROM pg_get_wal_summarizer_state();
summarized_tli | summarized_lsn | pending_lsn | summarizer_pid
----------------+----------------+-------------+----------------
0 | 0/0 | 0/0 | (null)
(1 row)
=# ALTER SYSTEM SET summarize_wal TO on;
ALTER SYSTEM
=# SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
=# SELECT * FROM pg_get_wal_summarizer_state();
summarized_tli | summarized_lsn | pending_lsn | summarizer_pid
----------------+----------------+-------------+----------------
1 | 0/1492D80 | 0/1492DF8 | 12228
(1 row)
The attached patch adds a GUC check hook to ensure summarize_wal cannot be
enabled when wal_level is minimal, fixing the issue.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From db4d879819417cade323249d6f68a1bef635857e Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Wed, 3 Jul 2024 20:17:42 +0900
Subject: [PATCH v1] Prevent summarize_wal from enabling when wal_level is
minimal.
WAL summarization should not be enabled if wal_level is set to minimal.
At startup, the postmaster checks these settings and exits with an error
if they are not configured properly. However, previously,
summarize_wal could be set to true after the server started with
wal_level = minimal, causing issues.
This commit adds a GUC check hook to ensure summarize_wal cannot
be enabled when wal_level is minimal.
---
src/backend/postmaster/walsummarizer.c | 16 +++++++++++++++-
src/backend/utils/misc/guc_tables.c | 2 +-
src/include/utils/guc_hooks.h | 1 +
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/backend/postmaster/walsummarizer.c
b/src/backend/postmaster/walsummarizer.c
index 55dc2ea8f5..806daba5ea 100644
--- a/src/backend/postmaster/walsummarizer.c
+++ b/src/backend/postmaster/walsummarizer.c
@@ -44,7 +44,7 @@
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "storage/shmem.h"
-#include "utils/guc.h"
+#include "utils/guc_hooks.h"
#include "utils/memutils.h"
#include "utils/wait_event.h"
@@ -1536,3 +1536,17 @@ MaybeRemoveOldWalSummaries(void)
}
}
}
+
+/*
+ * GUC check_hook for summarize_wal
+ */
+bool
+check_summarize_wal(bool *newval, void **extra, GucSource source)
+{
+ if (*newval && wal_level == WAL_LEVEL_MINIMAL)
+ {
+ GUC_check_errmsg("WAL cannot be summarized when \"wal_level\"
is \"minimal\"");
+ return false;
+ }
+ return true;
+}
diff --git a/src/backend/utils/misc/guc_tables.c
b/src/backend/utils/misc/guc_tables.c
index d28b0bcb40..607e9856de 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1781,7 +1781,7 @@ struct config_bool ConfigureNamesBool[] =
},
&summarize_wal,
false,
- NULL, NULL, NULL
+ check_summarize_wal, NULL, NULL
},
{
diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h
index 070d3f2a1a..83bf040ddf 100644
--- a/src/include/utils/guc_hooks.h
+++ b/src/include/utils/guc_hooks.h
@@ -138,6 +138,7 @@ extern bool check_ssl(bool *newval, void **extra, GucSource
source);
extern bool check_stage_log_stats(bool *newval, void **extra, GucSource
source);
extern bool check_subtrans_buffers(int *newval, void **extra,
GucSource
source);
+extern bool check_summarize_wal(bool *newval, void **extra, GucSource source);
extern bool check_synchronous_standby_names(char **newval, void **extra,
GucSource source);
extern void assign_synchronous_standby_names(const char *newval, void *extra);
--
2.45.1