欢迎投稿

今日深度:

监控SQL Server的运行状况(1)(2)

内存瓶颈

开始内存压力检测和调查之前,请确保已启用 SQL Server 中的高级选项。请先对 master 数据库运行以下查询以启用此选项。

  1. sp_configure 'show advanced options' 
  2. go 
  3. sp_configure 'show advanced options', 1 
  4. go 
  5. reconfigure 
  6. go 

首先运行以下查询以检查内存相关配置选项。

  1. sp_configure 'awe_enabled' 
  2. go 
  3. sp_configure 'min server memory' 
  4. go 
  5. sp_configure 'max server memory' 
  6. go 
  7. sp_configure 'min memory per query' 
  8. go 
  9. sp_configure 'query wait' 
  10. go 

运行下面的 DMV 查询以查看 CPU、计划程序内存和缓冲池信息。

  1. select  
  2. cpu_count, 
  3. hyperthread_ratio, 
  4. scheduler_count, 
  5. physical_memory_in_bytes / 1024 / 1024 as physical_memory_mb, 
  6. virtual_memory_in_bytes / 1024 / 1024 as virtual_memory_mb, 
  7. bpool_committed * 8 / 1024 as bpool_committed_mb, 
  8. bpool_commit_target * 8 / 1024 as bpool_target_mb, 
  9. bpool_visible * 8 / 1024 as bpool_visible_mb 
  10. from sys.dm_os_sys_info 

I/O 瓶颈

检查闩锁等待统计信息以确定 I/O 瓶颈。运行下面的 DMV 查询以查找 I/O 闩锁等待统计信息。

  1. select wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms, wait_time_ms / waiting_tasks_count 
  2. from sys.dm_os_wait_stats   
  3. where wait_type like 'PAGEIOLATCH%'  and waiting_tasks_count > 0 
  4. order by wait_type 

如果 waiting_task_countswait_time_ms 与正常情况相比有显著变化,则可以确定存在 I/O 问题。获取 SQL Server 平稳运行时性能计数器和主要 DMV 查询输出的基线非常重要。

这些 wait_types 可以指示您的 I/O 子系统是否遇到瓶颈。

使用以下 DMV 查询来查找当前挂起的 I/O 请求。请定期执行此查询以检查 I/O 子系统的运行状况,并隔离 I/O 瓶颈中涉及的物理磁盘。

  1. select  
  2.     database_id,  
  3.     file_id,  
  4.     io_stall, 
  5.     io_pending_ms_ticks, 
  6.     scheduler_address  
  7. from  sys.dm_io_virtual_file_stats(NULLNULL)t1, 
  8.         sys.dm_io_pending_io_requests as t2 
  9. where t1.file_handle = t2.io_handle 

在正常情况下,该查询通常不返回任何内容。如果此查询返回一些行,则需要进一步调查。

您还可以执行下面的 DMV 查询以查找 I/O 相关查询。

  1. select top 5 (total_logical_reads/execution_count) as avg_logical_reads, 
  2.                    (total_logical_writes/execution_count) as avg_logical_writes, 
  3.            (total_physical_reads/execution_count) as avg_physical_reads, 
  4.            Execution_count, statement_start_offset, p.query_plan, q.text 
  5. from sys.dm_exec_query_stats 
  6.       cross apply sys.dm_exec_query_plan(plan_handle) p 
  7.       cross apply sys.dm_exec_sql_text(plan_handle) as q 
  8. order by (total_logical_reads + total_logical_writes)/execution_count Desc 

下面的 DMV 查询可用于查找哪些批处理/请求生成的 I/O 最多。如下所示的 DMV 查询可用于查找可生成最多 I/O 的前五个请求。调整这些查询将提高系统性能。

  1. select top 5  
  2.     (total_logical_reads/execution_count) as avg_logical_reads, 
  3.     (total_logical_writes/execution_count) as avg_logical_writes, 
  4.     (total_physical_reads/execution_count) as avg_phys_reads, 
  5.      Execution_count,  
  6.     statement_start_offset as stmt_start_offset,  
  7.     sql_handle,  
  8.     plan_handle 
  9. from sys.dm_exec_query_stats   
  10. order by  (total_logical_reads + total_logical_writes) Desc 


www.htsjk.Com true http://www.htsjk.com/shujukugl/17743.html NewsArticle 内存瓶颈 开始内存压力检测和调查之前,请确保已启用 SQL Server 中的高级选项。请先对 master 数据库运行以下查询以启用此选项。 sp_configure 'showadvancedop...
评论暂时关闭