问题:当在Azure SQL的高级层上启用只读副本时,我们遇到了一些性能问题,这是非常奇怪且无法解释的。
我可以通过使用以下内置函数来查找是否正在只读副本上执行查询
DATABASEPROPERYEX(DB_NAME(),“可更新性”)
但是无法监视只读查询。
按照下面的文章,只读副本的预览中不支持扩展事件和查询存储 https://docs.microsoft.com/en-us/azure/sql-database/sql-database-read-scale-out
而以下文章建议读取横向扩展功能现在通常可用。仍然无法监视高级SQL数据库层中只读副本上执行的查询
我可以看到一个用户语音项目
还有其他选项可以监视只读工作负载吗?
答案 0 :(得分:1)
如前所述,您不能使用查询存储或扩展事件来监视只读副本上的查询,但仍可以使用sys.dm_exec_query_stats动态视图,例如,它可以为您提供CPU消耗最多的查询
SELECT TOP (25) MIN(query_stats.statement_text) AS [Statement Text],
SUM(query_stats.total_worker_time) / SUM(query_stats.execution_count) AS [Avg CPU Time],
query_stats.query_hash AS [Query Hash]
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
GROUP BY query_stats.query_hash
ORDER BY [Avg CPU Time] DESC;
您可以在以下查询中更改ORDER BY子句以监视其他资源:
SELECT TOP 10
(total_logical_reads/execution_count) AS avg_logical_reads,
(total_logical_writes/execution_count) AS avg_logical_writes,
(total_physical_reads/execution_count) AS avg_phys_reads,
(total_worker_time/execution_count) AS avg_cpu_over_head,
total_logical_reads, total_logical_writes, total_physical_reads,
total_worker_time, execution_count, total_elapsed_time AS Duration,
plan_generation_num AS num_recompiles,
statement_start_offset AS stmt_start_offset,
(SELECT SUBSTRING(text, statement_start_offset/2 + 1,
(CASE WHEN statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(MAX),text)) * 2
ELSE statement_end_offset
END - statement_start_offset)/2)
FROM sys.dm_exec_sql_text(sql_handle)) AS query_text,
(SELECT query_plan FROM sys.dm_exec_query_plan(plan_handle)) AS query_plan
FROM sys.dm_exec_query_stats a
--JUST CHANGE THE ORDER BY TO GET THE OTHER RESOURCES
ORDER BY (total_logical_reads + total_logical_writes)/execution_count DESC
您可能希望存储上述查询的结果,以供以后分析。