gpt4 book ai didi

sql-server - SQL Azure 读取横向扩展功能 : Monitor queries on read-only replica

转载 作者:行者123 更新时间:2023-12-01 03:12:23 25 4
gpt4 key购买 nike

问题 :在 azure SQL 的高级层上启用只读副本时,我们遇到了一些性能问题,这是非常奇怪且无法解释的。

我可以使用以下内置函数查找是否正在只读副本上执行查询

DATABASEPROPERYEX(DB_NAME(),'Updateability')



但是,无法监控只读查询。

根据以下文章,只读副本的预览版不支持扩展事件和查询存储
https://docs.microsoft.com/en-us/azure/sql-database/sql-database-read-scale-out

而下面的文章表明读取横向扩展功能现在普遍可用。我仍然无法监控在高级 SQL 数据库层中的只读副本上执行的查询

https://azure.microsoft.com/en-in/roadmap/azure-sql-database-announces-preview-of-read-scale-out-support-in-premium-service/

我可以看到用户语音项目

https://feedback.azure.com/forums/217321-sql-database/suggestions/34337935-monitor-queries-on-secondary-database-when-read-sc

还有其他选项可以监控只读工作负载吗?

最佳答案

正如您提到的,您不能使用查询存储或扩展事件来监视只读副本上的查询,但仍然可以使用 sys.dm_exec_query_stats动态 View ,它可以为您提供例如 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

您可能希望存储上述查询的结果以供以后分析。

关于sql-server - SQL Azure 读取横向扩展功能 : Monitor queries on read-only replica,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51062304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com