华为云云数据库rdsRDS SQL Server支持DMV动态管理视图_云淘科技
RDS for SQL Server支持DMV动态管理视图,方便用户快速查询实例上性能消耗最高的10条SQL语句。
操作场景
数据库执行效率较低。
某些时段的CPU,IO较高。
操作步骤
登录SQL SERVER客户端,通过rdsuser帐号连接目标实例,在管理面中执行以下SQL语句。
declare @DatabaseName nvarchar(100) set @DatabaseName = 'Wisdom_TT_ODS' select top 100 DB_NAME(st.dbid) as DBName, OBJECT_NAME(st.objectid,st.dbid) as ObjectName, substring(st.text,(qs.statement_start_offset/2)+1,((case qs.statement_end_offset when -1 then datalength(st.text) else qs.statement_end_offset end - qs.statement_start_offset)/2) + 1) as Statement, st.text as Query, qp.query_plan, plan_generation_num, creation_time, last_execution_time, execution_count, total_worker_time, min_worker_time, max_worker_time, total_logical_reads, min_logical_reads, max_logical_reads, total_elapsed_time, min_elapsed_time, max_elapsed_time, total_rows, min_rows, max_rows, total_worker_time/execution_count as avg_worker_time, --平均CPU耗时 total_logical_reads/execution_count as avg_logical_reads, --平均逻辑读 total_elapsed_time/execution_count as avg_elapsed_time, --平均总耗时 total_rows/execution_count as avg_rows, --平均处理数据行 sql_handle, plan_handle, query_hash, query_plan_hash from sys.dm_exec_query_stats qs cross apply sys.dm_exec_sql_text(plan_handle) st cross apply sys.dm_exec_query_plan(plan_handle) qp where st.dbid=DB_ID(@DatabaseName) and text not like '%sys.%'and text not like '%[[]sys]%' order by avg_worker_time desc
查看结果中对应数据库的SQL执行记录及资源消耗情况。
父主题: RDS for SQL Server
同意关联代理商云淘科技,购买华为云产品更优惠(QQ 78315851)
内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家