Re: log_min_messages per backend type - Mailing list pgsql-hackers
From | Euler Taveira |
---|---|
Subject | Re: log_min_messages per backend type |
Date | |
Msg-id | 313aa202-b5fa-4e3f-95d0-83425575c66d@app.fastmail.com Whole thread Raw |
In response to | Re: log_min_messages per backend type (Álvaro Herrera <alvherre@alvh.no-ip.org>) |
Responses |
Re: log_min_messages per backend type
Re: log_min_messages per backend type |
List | pgsql-hackers |
On Wed, Feb 5, 2025, at 3:51 PM, Álvaro Herrera wrote:
On 2024-Dec-17, Euler Taveira wrote:> Sometimes you need to inspect some debug messages from autovacuum worker but> you cannot apply the same setting for backends (that could rapidly fill the log> file). This proposal aims to change log_min_messages to have different log> levels depending on which backend type the message comes from.>> The syntax was changed from enum to string and it accepts a list of elements.>> Instead of enum, it now accepts a comma-separated list of elements (string).> Each element is LOGLEVEL:BACKENDTYPE.This format seems unintuitive. I would have thought you do it the otherway around, "backendtype:loglevel" ... that seems more natural becauseit's like assigning the 'loglevel' value to the 'backendtype' element.SET log_min_messages TO 'checkpointer:debug2, autovacuum:debug1';
Alvaro, thanks for your feedback. Your suggestion makes sense to me.
I dislike the array of names in variable.c. We already have an array inlaunch_backend.c (child_process_kinds), plus GetBackendTypeDesc inmiscinit.c. Maybe not for this patch to clean up though.
I thought about using child_process_kinds but two details made me give
up on the idea: (a) multiple names per backend type (for example,
B_BACKEND, B_DEAD_END_BACKEND, B_STANDALONE_BACKEND) and (b) spaces into
names. Maybe we should have a group into child_process_kinds but as you
said it seems material for another patch.
I think it should be acceptable to configure one global setting withexceptions for particular backend types:log_min_messages = WARNING, autovacuum:DEBUG1Right now I think the code only accepts the unadorned log level if thereare no other items in the list. I think the proposal downthread is touse the keyword ALL for this,log_min_messages = all:WARNING, autovacuum:DEBUG1 # I don't like thisbut I think it's inferior, because then "all" is not really "all", and Ithink it would be different if I had saidlog_min_messages = autovacuum:DEBUG1, all:WARNING # I don't like thisbecause it looks like the "all" entry should override the one I set forautovacuum before, which frankly would not make sense to me.
Good point. After reflection, I agree that "all" is not a good keyword.
This patch turns backend type as optional so WARNING means apply this
log level as a final step to the backend types that are not specified in
the list.
So I think these two lines,log_min_messages = WARNING, autovacuum:DEBUG1log_min_messages = autovacuum:DEBUG1, WARNINGshould behave identically and mean "set the level for autovacuum toDEBUG1, and to any other backend type to WARNING.
Done.
Also, I think it'd be better to reject duplicates in the list. Rightnow it looks like the last entry for one backend type overrides priorones. I meanlog_min_messages = autovacuum:DEBUG1, autovacuum:ERRORwould set autovacuum to error, but that might be mistake prone if yourstring is long. So implementation-wise I suggest to initialize thewhole newlogminmsgs array to -1, then scan the list of entries (savingan entry without backend type as the one to use later and) setting everybackend type to the number specified; if we see trying to set a valuethat's already different from -1, throw error. After scanning the wholelog_min_messages array, we scan the newlogminmsgs and set any entriesthat are still -1 to the value that we saved before.The new code in variable.c should be before the /* DATESTYLE */ commentrather than at the end of the file.
It was added into the MISCELLANEOUS section.
You still have many XXX comments. Also, postgresql.conf should list thevalid values for backendtype, as well as show an example of a validsetting. Please don't use ALLCAPS backend types in the docs, this looksugly:> + Valid <literal>BACKENDTYPE</literal> values are <literal>ARCHIVER</literal>,> + <literal>AUTOVACUUM</literal>, <literal>BACKEND</literal>,> + <literal>BGWORKER</literal>, <literal>BGWRITER</literal>,> + <literal>CHECKPOINTER</literal>, <literal>LOGGER</literal>,> + <literal>SLOTSYNCWORKER</literal>, <literal>WALRECEIVER</literal>,> + <literal>WALSENDER</literal>, <literal>WALSUMMARIZER</literal>, and> + <literal>WALWRITER</literal>.
Done.
Just to recap what was changed:
- patch was rebased
- backend type is optional and means all unspecified backend types
- generic log level (without backend type) is mandatory and the order it
ppears is not important (it is applied for the remaining backend types)
- fix Windows build
- new tests to cover the changes
Attachment
pgsql-hackers by date: