内存瓶颈
开始内存压力检测和调查之前,请确保已启用 SQL Server 中的高级选项。请先对 master 数据库运行以下查询以启用此选项。
- sp_configure 'show advanced options'
- go
- sp_configure 'show advanced options', 1
- go
- reconfigure
- go
首先运行以下查询以检查内存相关配置选项。
- sp_configure 'awe_enabled'
- go
- sp_configure 'min server memory'
- go
- sp_configure 'max server memory'
- go
- sp_configure 'min memory per query'
- go
- sp_configure 'query wait'
- go
运行下面的 DMV 查询以查看 CPU、计划程序内存和缓冲池信息。
- select
- cpu_count,
- hyperthread_ratio,
- scheduler_count,
- physical_memory_in_bytes / 1024 / 1024 as physical_memory_mb,
- virtual_memory_in_bytes / 1024 / 1024 as virtual_memory_mb,
- bpool_committed * 8 / 1024 as bpool_committed_mb,
- bpool_commit_target * 8 / 1024 as bpool_target_mb,
- bpool_visible * 8 / 1024 as bpool_visible_mb
- from sys.dm_os_sys_info
I/O 瓶颈
检查闩锁等待统计信息以确定 I/O 瓶颈。运行下面的 DMV 查询以查找 I/O 闩锁等待统计信息。
- select wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms, wait_time_ms / waiting_tasks_count
- from sys.dm_os_wait_stats
- where wait_type like 'PAGEIOLATCH%' and waiting_tasks_count > 0
- order by wait_type
如果 waiting_task_counts 和 wait_time_ms 与正常情况相比有显著变化,则可以确定存在 I/O 问题。获取 SQL Server 平稳运行时性能计数器和主要 DMV 查询输出的基线非常重要。
这些 wait_types 可以指示您的 I/O 子系统是否遇到瓶颈。
使用以下 DMV 查询来查找当前挂起的 I/O 请求。请定期执行此查询以检查 I/O 子系统的运行状况,并隔离 I/O 瓶颈中涉及的物理磁盘。
- select
- database_id,
- file_id,
- io_stall,
- io_pending_ms_ticks,
- scheduler_address
- from sys.dm_io_virtual_file_stats(NULL, NULL)t1,
- sys.dm_io_pending_io_requests as t2
- where t1.file_handle = t2.io_handle
在正常情况下,该查询通常不返回任何内容。如果此查询返回一些行,则需要进一步调查。
您还可以执行下面的 DMV 查询以查找 I/O 相关查询。
- select top 5 (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_physical_reads,
- Execution_count, statement_start_offset, p.query_plan, q.text
- from sys.dm_exec_query_stats
- cross apply sys.dm_exec_query_plan(plan_handle) p
- cross apply sys.dm_exec_sql_text(plan_handle) as q
- order by (total_logical_reads + total_logical_writes)/execution_count Desc
下面的 DMV 查询可用于查找哪些批处理/请求生成的 I/O 最多。如下所示的 DMV 查询可用于查找可生成最多 I/O 的前五个请求。调整这些查询将提高系统性能。
- select top 5
- (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,
- Execution_count,
- statement_start_offset as stmt_start_offset,
- sql_handle,
- plan_handle
- from sys.dm_exec_query_stats
- order by (total_logical_reads + total_logical_writes) Desc
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。