答复: empty,query_id, pg_stat_activity
zhouenbing <zhouenbing@sunwoda-evb.com>
From: "zhouenbing" <zhouenbing@sunwoda-evb.com>
To: "'Michael Paquier'" <michael@paquier.xyz>, "'Greg Sabino Mullane'" <htamfids@gmail.com>
Cc: <pgsql-bugs@lists.postgresql.org>
Date: 2025-09-04T03:32:18Z
Lists: pgsql-bugs
hello Michael The application scenario for performing performance analysis on Postgres through query_id is as follows: First, monitor the events and query_ids of the active database sessions during the current or past period by using the pg_stat_activity or pg_active_session_history views to analyze performance issues. Then, quickly locate the detailed execution information of the SQL statements by using the query_id of the session SQL in the pg_stat_statements. Aggregate and statistically analyze the performance of the SQL at different time points in the past by aggregating in pg_stat_statements_history within the specified time period. However, at present, some active sessions in pg_stat_activity have empty query_ids, which leads to many query_ids being empty in pg_active_session_history as well. If Mr. Greg said that empty query_ids indicate that the session SQL has not been executed, then I will exclude the sessions with empty query_ids. But I think that if the SQL has not been executed, the session status should be 'inactive' instead.