This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.
Introduction:
Recently, due to security and privacy compliance, Query Text is no longer shown on Query Performance insights for Azure PostgreSQL and Azure MySQL. this to help avoiding unauthorized access to the query text, preventing any expose to the underlying schema, and minimizing the security risks.
In this blog article, we will provide some SQL/KQL queries to get more insights on the running queries. and how to obtain the Query text from the database.
Solution:
Although query text is not available on the query performance insight portal, you still can use the Query Performance insights to obtain the query ID, and then you can obtain the query text by connecting to azure_sys database on your PostgreSQL Server and query on 'query_store.query_texts_view'. as shown in below figures:
You can use below query to get the top 10 query, you can also adjust the order by clause to your preferences:
P.S:- for Azure MySQL, you can use mysql.query_store and mysql.query_store_wait_stats to view the query text, more information can be found at: Query Performance Insight - Azure Database for MySQL | Microsoft Docs
When you enable Query Store - Azure Database for PostgreSQL - Single Server | Microsoft Docs, you can use the log analytics premade KQL queries or custom queries to get more insights on the running queries, As shown in below screenshots.
Note:- Allow up to 20 minutes for the first batch of data to persist in the azure_sys database.
In Addition, You can enable diagnostic settings for your Postgres server, Diagnostic settings allows you to send your Postgres logs in JSON format to Azure Monitor Logs for analytics and alerting, Event Hubs for streaming, and Azure Storage for archiving. The log categories to configure are QueryStoreRuntimeStatistics and QueryStoreWaitStatistics.
Query example #1:
Query example #2:
Sample output:
Query example #3:
You can use query below to check specific query based on query id, you need to update the server name, and query id.
Sample output:
Additional References:
Monitor and tune - Azure Database for PostgreSQL - Single Server | Microsoft Docs
Logs - Azure Database for PostgreSQL - Single Server | Microsoft Docs
Query Store - Azure Database for PostgreSQL - Single Server | Microsoft Docs
Query Performance Insight - Azure Database for PostgreSQL - Single Server | Microsoft Docs
Disclaimer
Please note that products and options presented in this article are subject to change. This article reflects the query performance insights available for Azure database for PostgreSQL in March, 2022.
Closing remarks
We hope you find this article helpful. If you have any feedback, please do not hesitate to provide it in the comment section below.
Ahmed S. Mazrouh
