zoukankan      html  css  js  c++  java
  • 来自微软TetchNet 监控 SQL Server (2005/2008) 的运行状况

    http://technet.microsoft.com/zh-cn/library/bb838723.aspx

    Microsoft SQL Server 2005 提供了一些工具来监控数据库。方法之一是动态管理视图。动态管理视图 (DMV) 和动态管理函数 (DMF) 返回的服务器状态信息可用于监控服务器实例的运行状况、诊断问题和优化性能。

    常规服务器动态管理对象包括:

    • dm_db_*:数据库和数据库对象

    • dm_exec_*:执行用户代码和关联的连接

    • dm_os_*:内存、锁定和时间安排

    • dm_tran_*:事务和隔离

    • dm_io_*:网络和磁盘的输入/输出

    此部分介绍为监控 SQL Server 运行状况而针对这些动态管理视图和函数运行的一些常用查询。


    摘录部分精彩SQL如下:

    下面的查询显示 CPU 平均占用率最高的前 50 个 SQL 语句。

    SELECT TOP 50
    total_worker_time
    /execution_count AS [Avg CPU Time],
    (
    SELECT SUBSTRING(text,statement_start_offset/2,(CASE WHEN statement_end_offset = -1 then LEN(CONVERT(nvarchar(max), text)) * 2 ELSE statement_end_offset end -statement_start_offset)/2FROM sys.dm_exec_sql_text(sql_handle)) AS query_text, *
    FROM sys.dm_exec_query_stats 
    ORDER BY [Avg CPU Time] DESC


    下面的查询显示一些可能占用大量 CPU 使用率的运算符(例如 ‘%Hash Match%’、‘%Sort%’)以找出可疑对象。

    复制代码
    select *
    from 
          sys.dm_exec_cached_plans
          
    cross apply sys.dm_exec_query_plan(plan_handle)
    where 
          
    cast(query_plan as nvarchar(max)) like '%Sort%'
          
    or cast(query_plan as nvarchar(max)) like '%Hash Match%'
    复制代码


    运行下面的 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
    复制代码


    下面的示例查询显示已重新编译的前 25 个存储过程。plan_generation_num 指示该查询已重新编译的次数。

    复制代码
    select top 25
    sql_text.
    text,
    sql_handle,
    plan_generation_num,
    execution_count,
    dbid,
    objectid 
    from sys.dm_exec_query_stats a
    cross apply sys.dm_exec_sql_text(sql_handle) as sql_text
    where plan_generation_num > 1
    order by plan_generation_num 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

    Audit Logout 占用大量内存,cpu资源,怎么样能够降低这个进程消耗的资源,因为这个服务器拖的很厉害,哪位大侠有解决这个问题的比较好的解决方案,分数不是问题....

    1)发生原因:http://blog.joycode.com/ghj/archive/2008/11/24/115360.joy

    2)解决方法:

    1、dbcc checkdb 重建索引

    2、sp_lock  檢查有沒有死鎖

    3、A CPU bottleneck that happens suddenly and unexpectedly, without additional load on the server, is commonly caused by a nonoptimal query plan, a poor configuration, or design factors, and not insufficient hardware resources. Before rushing out to buy faster and/or more processors, you should first identify the largest consumers of CPU bandwidth and see if they can be tuned.

    http://technet.microsoft.com/zh-cn/library/cc966540(en-us).aspx

    4、用pssdig抓一下,然后在RMLUtils中看消耗cpu的用户和数据库以及对应的程序。

    5、在这个事件类别里面看到的CPU数不是指aduit logout所使用的cpu时间,而是指该该连接在连接期内所使用的CPU的总数。再仔细的Profiler一下。

    6、看看产生aduit logout事件的是否来自同一个进程

    引自:http://topic.csdn.net/u/20090504/11/0440a9e3-3b0b-4708-b5bc-e4611616ba65.html

  • 相关阅读:
    【转】svn冲突问题详解 SVN版本冲突解决详解
    【转】Mysql解决The total number of locks exceeds the lock table size错误
    【转】iOS中修改AVPlayer的请求头信息
    【转】AJAX请求和普通HTTP请求区别
    【转】怎么给javascript + div编辑框光标位置插入表情文字等?
    【转】iOS开发笔记--识别单击还是双击
    【转】Android hdpi ldpi mdpi xhdpi xxhdpi适配详解
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
  • 原文地址:https://www.cnblogs.com/zcm123/p/2780719.html
Copyright © 2011-2022 走看看