Subject: Re: log_min_messages per backend type

From: "Euler Taveira" <[email-masked]>
Date: Tue, 10 Feb 2026 19:05:30 -0300

On Mon, Feb 9, 2026, at 10:03 AM, Alvaro Herrera wrote:
> On 2026-Feb-09, Alvaro Herrera wrote:
>
>> I just pushed this, and somehow I forgot to squash this into the commit.
>> I don't think it matters terribly much though, so I'm going to hang onto
>> this for a while in case some bug is found.
>
> Euler mentioned offlist that I also forgot to remove
> log_min_messages_process_types from guc.h.  So that gives us this patch
> for now.
>

I expanded this patch a bit with fixes proposed by Man Zeng and Noriyoshi
Shinoda. Besides these changes, I noticed that

* default value in uppercase: since we changed the vartype from enum to string
  and enum maps DEBUG1 to "debug1" (see server_message_level_options), it
  should use the lowercase string to keep the same output as previous versions.
  There is no bug here. It is just a matter of keeping the same output.
* use single quote: since we changed the vartype from enum to string, we should
  add single quotes. If you don't add single quotes, it works (for a single
  default log level) -- as exercised in the tests. However, as soon as the user
  adds an extra element it fails. This avoids confusion.

$ psql
psql (19devel)
Type "help" for help.

postgres=# show log_min_messages;
 log_min_messages 
------------------
 WARNING
(1 row)

postgres=# set log_min_messages to debug1;
SET
postgres=# show log_min_messages;
 log_min_messages 
------------------
 debug1
(1 row)

postgres=# set log_min_messages to 'debug1';
SET
postgres=# show log_min_messages;
 log_min_messages 
------------------
 debug1
(1 row)

postgres=# set log_min_messages to warning, backend:error;
ERROR:  syntax error at or near ":"
LINE 1: set log_min_messages to warning, backend:error;
                                                ^
postgres=# set log_min_messages to 'warning, backend:error';
SET
postgres=# show log_min_messages;
    log_min_messages    
------------------------
 warning, backend:error
(1 row)

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

From a9984718bed8f2fd7e6ba3c096a07349948a0598 Mon Sep 17 00:00:00 2001
From: Euler Taveira <[email-masked]>
Date: Tue, 10 Feb 2026 11:39:56 -0300
Subject: [PATCH] Minor cleanups in log_min_messages

Fix some issues in commit 38e0190ced7. Remove an unused variable. Use
"default log level" consistently. Keep the process types in alphabetical
order.  Since log_min_messages type was changed from enum to string, it
is a good idea to use single quotes. Although it works for a single
default log level, it will fail as soon as the user tries to add an
extra element to the value. Using single quotes minimizes the chance of
confusion. Use lowercase string for the default value to keep the same
output as previous versions.
---
 doc/src/sgml/config.sgml                      |  2 +-
 src/backend/utils/error/elog.c                | 14 +++++++-------
 src/backend/utils/misc/guc_parameters.dat     |  2 +-
 src/backend/utils/misc/postgresql.conf.sample |  2 +-
 src/include/postmaster/proctypelist.h         |  2 +-
 src/include/utils/guc.h                       |  2 --
 6 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 37342986969..61d39fd3366 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7145,9 +7145,9 @@ local0.*    /var/log/postgresql
          <member><literal>checkpointer</literal></member>
          <member><literal>ioworker</literal></member>
          <member><literal>postmaster</literal></member>
-         <member><literal>syslogger</literal></member>
          <member><literal>slotsyncworker</literal></member>
          <member><literal>startup</literal></member>
+         <member><literal>syslogger</literal></member>
          <member><literal>walreceiver</literal></member>
          <member><literal>walsender</literal></member>
          <member><literal>walsummarizer</literal></member>
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 129906e2daa..59315e94e3e 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2190,7 +2190,7 @@ check_log_min_messages(char **newval, void **extra, GucSource source)
 	char	   *result;
 	int			newlevel[BACKEND_NUM_TYPES];
 	bool		assigned[BACKEND_NUM_TYPES] = {0};
-	int			genericlevel = -1;	/* -1 means not assigned */
+	int			defaultlevel = -1;	/* -1 means not assigned */
 
 	const char *const process_types[] = {
 #define PG_PROCTYPE(bktype, bkcategory, description, main_func, shmem_attach) \
@@ -2228,8 +2228,8 @@ check_log_min_messages(char **newval, void **extra, GucSource source)
 			const struct config_enum_entry *entry;
 			bool		found;
 
-			/* Reject duplicates for generic log level. */
-			if (genericlevel != -1)
+			/* Reject duplicates for default log level. */
+			if (defaultlevel != -1)
 			{
 				GUC_check_errdetail("Redundant specification of default log level.");
 				goto lmm_fail;
@@ -2241,7 +2241,7 @@ check_log_min_messages(char **newval, void **extra, GucSource source)
 			{
 				if (pg_strcasecmp(entry->name, elem) == 0)
 				{
-					genericlevel = entry->val;
+					defaultlevel = entry->val;
 					found = true;
 					break;
 				}
@@ -2331,9 +2331,9 @@ lmm_fail:
 	}
 
 	/*
-	 * The generic log level must be specified. It is the fallback value.
+	 * The default log level must be specified. It is the fallback value.
 	 */
-	if (genericlevel == -1)
+	if (defaultlevel == -1)
 	{
 		GUC_check_errdetail("Default log level was not defined.");
 		guc_free(rawstring);
@@ -2345,7 +2345,7 @@ lmm_fail:
 	for (int i = 0; i < BACKEND_NUM_TYPES; i++)
 	{
 		if (!assigned[i])
-			newlevel[i] = genericlevel;
+			newlevel[i] = defaultlevel;
 	}
 
 	/*
diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat
index 762b8efe6b0..4b8bd57d1e7 100644
--- a/src/backend/utils/misc/guc_parameters.dat
+++ b/src/backend/utils/misc/guc_parameters.dat
@@ -1698,7 +1698,7 @@
   long_desc => 'Each level includes all the levels that follow it. The later the level, the fewer messages are sent.',
   flags => 'GUC_LIST_INPUT',
   variable => 'log_min_messages_string',
-  boot_val => '"WARNING"',
+  boot_val => '"warning"',
   check_hook => 'check_log_min_messages',
   assign_hook => 'assign_log_min_messages',
 },
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 6e82c8e055d..12183f6996f 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -532,7 +532,7 @@
 
 # - When to Log -
 
-#log_min_messages = warning             # comma-separated list of
+#log_min_messages = 'warning'           # comma-separated list of
                                         # process_type:level entries, plus
                                         # one freestanding level as default.
                                         # Valid process types are:
diff --git a/src/include/postmaster/proctypelist.h b/src/include/postmaster/proctypelist.h
index 4e259e84c2d..feac19ba207 100644
--- a/src/include/postmaster/proctypelist.h
+++ b/src/include/postmaster/proctypelist.h
@@ -26,7 +26,7 @@
 
 /*
  * List of process types (symbol, category, description, Main function,
- * shmem_attach, message level) entries.
+ * shmem_attach) entries.
  */

diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 8acbdba7ff5..c46203fabfe 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -329,8 +329,6 @@ extern PGDLLIMPORT bool trace_sort;
 extern PGDLLIMPORT bool optimize_bounded_sort;
 #endif
 
-extern PGDLLIMPORT const char *const log_min_messages_process_types[];
-
 /*
  * Declarations for options for enum values
  *
-- 
2.39.5