Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>
Cc: Atsushi Torikoshi <atorik(at)gmail(dot)com>, Tatsuro Yamada <tatsuro(dot)yamada(dot)tf(at)nttcom(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Bruce Momjian <bruce(at)momjian(dot)us>, Evgeny Efimkin <efimkin(at)yandex-team(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?
Date: 2020-08-19 14:19:30
Message-ID: 20200819141930.n33w6qbap7udm7b6@nol
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 28, 2020 at 10:55:04AM +0200, Julien Rouhaud wrote:
> On Tue, Jul 28, 2020 at 10:07 AM torikoshia <torikoshia(at)oss(dot)nttdata(dot)com> wrote:
> >
> > Thanks for updating!
> > I tested the patch setting log_statement = 'all', but %Q in
> > log_line_prefix
> > was always 0 even when pg_stat_statements.queryid and
> > pg_stat_activity.queryid are not 0.
> >
> > Is this an intentional behavior?
> >
> >[...]
>
> Thanks for the tests! That's indeed an expected behavior (although I
> wasn't aware of it), which isn't documented in this patch (I'll fix
> it). The reason for that is that log_statements is done right after
> parsing the query:
>
> /*
> * Do basic parsing of the query or queries (this should be safe even if
> * we are in aborted transaction state!)
> */
> parsetree_list = pg_parse_query(query_string);
>
> /* Log immediately if dictated by log_statement */
> if (check_log_statement(parsetree_list))
> {
> ereport(LOG,
> (errmsg("statement: %s", query_string),
> errhidestmt(true),
> errdetail_execute(parsetree_list)));
> was_logged = true;
> }
>
> As parse analysis is not yet done, no queryid can be computed at that
> point, so we always print 0. That's a limitation that can't be
> removed without changing the semantics of log_statements, so we'll
> probably have to live with it.
>
> > And here is a minor typo.
> > optionnally -> optionally
> >
> >
> > > 753 + /* query identifier, optionnally computed using
> > > post_parse_analyze_hook */
>
> Thanks, I fixed it locally!

Recent conflict, rebased v11 attached.

Attachment Content-Type Size
v11-0001-Expose-queryid-in-pg_stat_activity-and-log_line_.patch text/x-diff 33.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-08-19 15:01:37 Re: Creating a function for exposing memory usage of backend process
Previous Message Michael Paquier 2020-08-19 13:55:45 Re: Creating a function for exposing memory usage of backend process