How to view history of queries (all OR over a long period) performed on database which is hosted on Azure?

白昼怎懂夜的黑 提交于 2020-12-29 00:44:42

问题


For a database hosted on Azure, i can view the recent history of the queries performed on it. This is through the Azure portal > Database > Manage > Administration > Query Performance.

Unfortunately, the history found there, only covers a small time frame (few minutes). I intend to create non-clustered indexes on my database and for that, need to get a log of the real queries run on the data on a typical day, as opposed to the past few minutes.

Currently, i have to keep refreshing the page many times and record all the queries for each refresh, Even then, the log which i obtain after this arduous process, only reflects a small subset of the queries performed. Is there any option to view histories for longer periods?

Thanks.


回答1:


Windows Azure SQL Database offers dynamic management views (DMVs) that return server state information that can be used to monitor the health of a server instance, diagnose problems, and tune performance.

For a list of available views refer to System Views (Windows Azure SQL Database).

For examples of how to find CPU-intensive queries, long-running queries and I/O intensive queries refer to Tuning SQL Azure Databases, Part 2.

For additional troubleshooting tips refer to Troubleshoot and Optimize Queries with Windows Azure SQL Database, Improving Your I/O Performance, Gaining Performance Insight into Windows Azure SQL Database, Troubleshooting Windows Azure SQL Database, Finding Blocking Queries in SQL Azure, March Madness – SQL Azure – sys.dm_exec_query_stats.

Also consider profiling at the application level, for instance as explained in Profiling Database Activity in the Entity Framework and Query Profiling SQL Azure when using Entity Framework or Linq-to-SQL.

For advanced monitoring consider deploying Windows Azure SQL Database Management Pack for System Center 2012.




回答2:


Here is a query I found useful to see the most executed queries on my Azure SQL Server database:

SELECT TOP 10 execution_count, statement_text
FROM (
    SELECT QS.*,
    SUBSTRING(
        ST.text,
        (QS.statement_start_offset/2) + 1,
        ((
            CASE statement_end_offset
            WHEN -1 THEN DATALENGTH(st.text)
            ELSE QS.statement_end_offset END
            - QS.statement_start_offset
        ) /2) 
        + 1
    ) AS statement_text
    FROM sys.dm_exec_query_stats AS QS
    CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) as ST
) AS query_stats
WHERE statement_text LIKE 'UPDATE%'
ORDER BY execution_count DESC

Source: March Madness - SQL Azure - sys.dm_exec_query_plan | SQLRockstar | Thomas LaRock



来源:https://stackoverflow.com/questions/17920968/how-to-view-history-of-queries-all-or-over-a-long-period-performed-on-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!