|
|
Get the SQL Text for a QueryID in Azure PostgreSQL.
Date created: August 2, 2026.
Problem Description. While reviewing long-running queries in Query Performance Insight for an Azure
Database for PostgreSQL Flexible Server, I collected several Query IDs. The
problem was that the Azure portal showed the identifiers, but not the SQL
statements behind them. SELECT query_sql_text However, replacing 1714541169297135157 with the Query IDs I had collected
returned no rows.
Cause. The Azure portal guidance is incomplete because Azure Query Store uses two different identifiers: query_id and query_text_id. They are both bigint values, but they are not interchangeable. The query_id can be located at query_store.qs_view and it represents a hash calculated from the parsed SQL statement. Meanwhile, query_text_id is related to the query_store.query_texts_view and identifies a row in the Query Store query-text table. In my case, the identifiers needed to be
matched against query_store.qs_view.query_id. Fortunately, qs_view already
contains both the Query ID and its associated query_sql_text, so no additional
join is required. Query Store views are available in the azure_sys database.
Workaround / SolutionConnect directly to the azure_sys database
using PgAdmin or any other tool and query query_store.qs_view.
One final detail is the query_sql_text is a
representative SQL statement. Query Store can group structurally equivalent
statements under the same query_id, especially when they differ only by literal
values. Therefore, the returned text may not include the exact parameter values
used during the slow execution.
|
|
.Send mail to
sqlcoffee.stretch737@simplelogin.com with
questions or comments about this web site.
|