Re: log_min_messages per backend type

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: japin <japinli(at)hotmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: log_min_messages per backend type
Date: 2026-01-17 22:02:47
Message-ID: 202601172159.zlzebobtb7kq@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Jan-15, Euler Taveira wrote:

> + /*
> + * Use a stable representation of log_min_messages. The generic level is
> + * always the first element and the other elements (type:level) are sorted
> + * by process type.
> + */
> + list_sort(elemlist, string_cmp);
> + foreach(l, elemlist)
> + {
> + char *tok = (char *) lfirst(l);
> +
> + if (strchr(tok, ':') == NULL)
> + {
> + elemlist = list_delete(elemlist, tok);
> + elemlist = lcons(tok, elemlist);
> + break;
> + }
> + }

> +static int
> +string_cmp(const ListCell *a, const ListCell *b)
> +{
> + const char *s = lfirst(a);
> + const char *t = lfirst(b);
> +
> + return strcmp(s, t);
> +}

I'm not opposed to this idea, but I think it should be implemented not
by sorting and then moving the first element to the top of the list, but
instead by modifying the cmp function so that the desired order is
achieved directly. So the cmp() should return -1 if element a has no
colon, or 1 if element b has no colon, otherwise return per strcmp.
That way you can remove the foreach() block above, which is icky.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Computing is too important to be left to men." (Karen Spärck Jones)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2026-01-18 02:53:17 Re: Import Statistics in postgres_fdw before resorting to sampling.
Previous Message Zsolt Parragi 2026-01-17 21:27:50 Re: Hackorum - a new mailing list frontend