Re: log_line_prefix: make it possible to add the search_path

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Pierre Ducroquet <p(dot)psql(at)pinaraf(dot)info>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: log_line_prefix: make it possible to add the search_path
Date: 2022-07-26 01:08:01
Message-ID: CAP53PkwiFaPYkqAA0aa2-VhthT6+RW5hJPi1EhEksqoZS_S-Jw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 25, 2022 at 12:38 AM Pierre Ducroquet <p(dot)psql(at)pinaraf(dot)info>
wrote:

> usecase by not showing the schema, one of them being log_line_prefix.
> It is possible to work around this using the application_name, but a
> mistake
> on the application side would be fatal, while the search_path would still
> indicate the real tables used in a query.
>

I'm assuming this is mostly referring to STATEMENT log lines and other
situations where the original query is output (e.g. auto_explain).

+1 on the benefit of solving this (I've had this use case before), but I
think we can keep this more specific than a general log_line_prefix option.
The search_path isn't relevant to any log line that doesn't reference a
query, since e.g. autovacuum log output fully qualifies its relation names,
and many other common log lines have nothing to do with tables or queries.

What if we instead had something like this, as an extra CONTEXT (or DETAIL)
log line:

LOG: duration: 4079.697 ms execute <unnamed>:
SELECT * FROM x WHERE y = $1 LIMIT $2
DETAIL: parameters: $1 = 'long string', $2 = '1'
CONTEXT: settings: search_path = 'my_tenant_schema, "$user", public'

That way you could determine that the slow query was affecting the "x"
table in "my_tenant_schema".

This log output would be controlled by a new GUC, e.g.
"log_statement_search_path" with three settings: (1) never, (2)
non_default, (3) always.

The default would be "never" (same as today). "non_default" would output
the search path when a SET has modified it in the current session (and so
we couldn't infer it from the config or the role/database overrides).
"always" would always output the search path for statement-related log
lines.

Thanks,
Lukas

--
Lukas Fittl

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2022-07-26 01:19:05 Re: Make name optional in CREATE STATISTICS
Previous Message Kyotaro Horiguchi 2022-07-26 00:42:23 Re: Remove useless arguments in ReadCheckpointRecord().