Re: query_id, pg_stat_activity, extended query protocol

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: "Imseih (AWS), Sami" <simseih(at)amazon(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Cc: kaido vaikla <kaido(dot)vaikla(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: query_id, pg_stat_activity, extended query protocol
Date: 2024-05-16 05:33:27
Message-ID: c4157df6-36a6-4442-87b8-7fabbcaeac5b@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 15.05.2024 10:24, Imseih (AWS), Sami wrote:
>> I discovered the current state of queryId reporting and found that it
>> may be unlogical: Postgres resets queryId right before query execution
>> in simple protocol and doesn't reset it at all in extended protocol and
>> other ways to execute queries.
>
> In exec_parse_message, exec_bind_message and exec_execute_message,
> the queryId is reset via pgstat_report_activity
>
>> I think we should generally report it when the backend executes a job
>> related to the query with that queryId. This means it would reset the
>> queryId at the end of the query execution.
>
> When the query completes execution and the session goes into a state
> other than "active", both the query text and the queryId should be of the
> last executed statement. This is the documented behavior, and I believe
> it's the correct behavior.
I discovered this case a bit.
As I can see, the origin of the problem is that the exec_execute_message
report STATE_RUNNING, although ExecutorStart was called in the
exec_bind_message routine beforehand.
I'm unsure if it needs to call ExecutorStart in the bind code. But if we
don't change the current logic, would it make more sense to move
pgstat_report_query_id to the ExecutorRun routine?

--
regards, Andrei Lepikhov

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message zaidagilist 2024-05-16 05:36:49 Re: PostgreSQL 17 Beta 1 release announcement draft
Previous Message Bertrand Drouvot 2024-05-16 05:15:58 Re: PostgreSQL 17 Beta 1 release announcement draft