Re: log_min_messages per backend type

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Euler Taveira <euler@eulerto.com>
Cc: japin <japinli@hotmail.com>, Andres Freund <andres@anarazel.de>, pgsql-hackers@lists.postgresql.org, Chao Li <li.evan.chao@gmail.com>
Date: 2026-02-06T11:05:27Z
Lists: pgsql-hackers

Attachments

Here are some fixups for the main patch.  I include yours so that CI
will test this one.

* I found some errdetail messages unclear, so I reworded them.
Specifically you had
 ERROR:  invalid value for parameter "log_min_messages": "backend:error, debug1, backend:warning"
 DETAIL:  Process type "backend" was already assigned.
which is not completely incorrect but looks weird from the user
perspective.  I changed it to
 DETAIL:  Redundant log level specification for process type "backend".

Also,
 ERROR:  invalid value for parameter "log_min_messages": "debug1, backend:error, fatal"
 DETAIL:  Generic log level was already assigned.
I changed to
 DETAIL:  Redundant specification of default log level.

and added process type in this one:
 ERROR:  invalid value for parameter "log_min_messages": "backend:error, checkpointer:bar, archiver:debug1"
 DETAIL:  Unrecognized log level: "bar".
changed to
 DETAIL:  Unrecognized log level for process type "checkpointer": "bar".
(This one can show an invalid process type if the level is also bogus.
I don't think that's a terrible problem.)

* I'm not fond of the term "generic", so I changed it to "default",
which IMO makes more sense from the user point of view.

* There seemed to be too much guc_mallocking[*] going on; for instance for
ptype.  I simplified that by just overwriting the : to a '\0', then we
can use the original string for pg_strcasecmp().  At the bottom of the
loop we restore the ':', so that the code below can reuse the original
values.  This is okay because we have already mallocked a copy for
SplitGUCList.

* There's no reason to add a WARNING to every process type in the
proctypelist.h table.  We can just set the values to WARNING in the
log_min_messages initializer in guc_tables.c.

* There's no reason AFAICS to have log_min_messages_process_types in
guc_tables.c; nobody else uses it.  I made it a local array of char*
inside the check_log_min_messages function.

* There's no need to initialize the newlevel[] array, since we're going
to assign values to every individual element at one point or another.
And for the assigned[] array, we don't need to set the value of each to
'false' in a loop; we can just initialize to '{0}' and the compiler will
do the needful.  With this we can remove the loop entirely.

* "guc_free()+list_free()+return false" the whole time in the various
failure places across the loop was tiresome.  I put them all in a single
place and jump there with a goto.

* in foreach() loops, tracking of a 'bool first' is unnecessary.  You
can just compare foreach_current_index() with 0.

* Rewrote docs and comments

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Cleanup for log_min_messages changes in 38e0190ced71

  2. Allow log_min_messages to be set per process type

  3. Assign "backend" type earlier during process start-up

  4. Use integer backend type when exec'ing a postmaster child

  5. Sort guc_parameters.dat alphabetically by name

  6. Create a separate file listing backend types

  7. Replace postmaster.c's own backend type codes with BackendType