DBA-常用到的动态视图分析语句

--语句1:获取前20逻辑读取次数或逻辑写入次数或CPU 时间
SELECT TOP 20 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_reads DESC -- 逻辑读取次数
 --ORDER BY qs.total_logical_writes DESC -- 逻辑写入次数
 --ORDER BY qs.total_worker_time DESC -- CPU 时间

--语句2:获取前20执行的 SP 命令的总工作时间 (CPU 压力)
    SELECT TOP 20 qt.text AS ‘SP Name‘, qs.total_worker_time AS ‘TotalWorkerTime‘,
    qs.total_worker_time/qs.execution_count AS ‘AvgWorkerTime‘,
    qs.execution_count AS ‘Execution Count‘,
    ISNULL(qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()), 0) AS ‘Calls/Second‘,
    ISNULL(qs.total_elapsed_time/qs.execution_count, 0) AS ‘AvgElapsedTime‘,
    qs.max_logical_reads, qs.max_logical_writes,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Age in Cache‘
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE qt.dbid = db_id() -- 当前数据库
    ORDER BY qs.total_worker_time DESC

--语句3: 获取前20 执行的 SP 命令逻辑写入/分钟
    SELECT TOP 20 qt.text AS ‘SP Name‘, qs.total_logical_writes, qs.total_logical_writes/qs.execution_count AS ‘AvgLogicalWrites‘,
    qs.total_logical_writes/DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Logical Writes/Min‘,
    qs.execution_count AS ‘Execution Count‘,
    qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()) AS ‘Calls/Second‘,
    qs.total_worker_time/qs.execution_count AS ‘AvgWorkerTime‘,
    qs.total_worker_time AS ‘TotalWorkerTime‘,
    qs.total_elapsed_time/qs.execution_count AS ‘AvgElapsedTime‘,
    qs.max_logical_reads, qs.max_logical_writes, qs.total_physical_reads,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Age in Cache‘,
    qs.total_physical_reads/qs.execution_count AS ‘Avg Physical Reads‘, qt.dbid
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE qt.dbid = db_id() -- 当前数据库
    ORDER BY qs.total_logical_writes DESC

--语句4: 获取前20执行的 SP 命令的逻辑读取(内存压力)
    SELECT TOP 20 qt.text AS ‘SP Name‘, total_logical_reads,
    qs.execution_count AS ‘Execution Count‘, total_logical_reads/qs.execution_count AS ‘AvgLogicalReads‘,
    qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()) AS ‘Calls/Second‘,
    qs.total_worker_time/qs.execution_count AS ‘AvgWorkerTime‘,
    qs.total_worker_time AS ‘TotalWorkerTime‘,
    qs.total_elapsed_time/qs.execution_count AS ‘AvgElapsedTime‘,
    qs.total_logical_writes,
    qs.max_logical_reads, qs.max_logical_writes, qs.total_physical_reads,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Age in Cache‘, qt.dbid
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE qt.dbid = db_id() -- 当前数据库
    ORDER BY total_logical_reads DESC

--语句5: 获取前20执行的 SP 命令由物理读取 (读取 I/O 压力)
    SELECT TOP 20 qt.text AS ‘SP Name‘, qs.total_physical_reads, qs.total_physical_reads/qs.execution_count AS ‘Avg Physical Reads‘,
    qs.execution_count AS ‘Execution Count‘,
    qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()) AS ‘Calls/Second‘,
    qs.total_worker_time/qs.execution_count AS ‘AvgWorkerTime‘,
    qs.total_worker_time AS ‘TotalWorkerTime‘,
    qs.total_elapsed_time/qs.execution_count AS ‘AvgElapsedTime‘,
    qs.max_logical_reads, qs.max_logical_writes,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Age in Cache‘, qt.dbid
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE qt.dbid = db_id() -- 当前数据库
    ORDER BY qs.total_physical_reads DESC

--语句6: 获取前20执行的 SP 命令执行计数
    SELECT TOP 20 qt.text AS ‘SP Name‘, qs.execution_count AS ‘Execution Count‘,
    qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()) AS ‘Calls/Second‘,
    qs.total_worker_time/qs.execution_count AS ‘AvgWorkerTime‘,
    qs.total_worker_time AS ‘TotalWorkerTime‘,
    qs.total_elapsed_time/qs.execution_count AS ‘AvgElapsedTime‘,
    qs.max_logical_reads, qs.max_logical_writes, qs.total_physical_reads,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS ‘Age in Cache‘
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE qt.dbid = db_id() -- Filter by current database
    ORDER BY qs.execution_count DESC
时间: 2024-11-08 21:02:24

DBA-常用到的动态视图分析语句的相关文章

oracle动态视图v$,v_$,gv$,gv_$与x$之间的关系

前言:在oracle运维的过程中,经常会使用到一些以V$开头的动态视图,比如V$session, 有一次偶然看到有人用V_$session, 初以为别人写错了,没想到desc v_$session以后能看到和v$session一样的结构,再以后又发现以gv$开头的视图等等.趁这次在一台Linux系统上装oracle的机会,终于弄清楚了这些动态视图与相应表之间的关系.这些都是由oracle自己管理的数据结构,得从v$fixed_table入手:[[email protected] admin]$

DBA_Oracle DBA常用表汇总(概念)

2014-06-20 BaoXinjian 一.与权限相关的字典 ALL_COL_PRIVS表示列上的授权,用户和PUBLIC是被授予者 ALL_COL_PRIVS_MADE表示列上的授权,用户是属主和被授予者 ALL_COL_RECD表示列上的授权,用户和PUBLIC是被授予者 ALL_TAB_PRIVS表示对象上的授权,用户是PUBLIC或被授予者或用户是属主 ALL_TAB_PRIVS_MADE表示对象上的权限,用户是属主或授予者 ALL_TAB_PRIVS_RECD表示对象上的权限,用户

Unity3D中常用的数据结构总结与分析

Unity3D中常用的数据结构总结与分析 c#语言规范 阅读目录 1.几种常见的数据结构 2.几种常见数据结构的使用情景 来到周末,小匹夫终于有精力和时间来更新下博客了.前段时间小匹夫读过一份代码,对其中各种数据结构灵活的使用赞不绝口,同时也大大激发了小匹夫对各种数据结构进行梳理和总结的欲望.正好最近也拜读了若干大神的文章,觉得总结下常用的数据结构以供自己也能灵活的使用变得刻不容缓.那么还是从小匹夫的工作内容入手,就谈谈在平时使用U3D时经常用到的数据结构和各种数据结构的应用场景吧. 回到目录

dba常用的sql

大牛dba用到的34条SQL语句 1.检查无效的数据文件 Select * from v$data_file; 2.执行失败或中断的Jobs select job, to_char(last_date,'yyyy-mm-dd hh24:mi:ss') "Last Date", to_char(this_date,'yyyy-mm-dd hh24:mi:ss') "This Date", broken,failures, schema_user, what from

<十五>UML核心视图动态视图之活动图

一:动态视图 --->动态视图是描述事物动态行为的. --->需要注意的是:动态视图不能够独立存在,它必需特指一个静态视图活uml元素,说明在静态视图规定的事物结构下它们的动态行为. --->动态视图:活动图,状态图,时序图,协作图 二:活动图 --->活动图描述了为了完成某一个目标需要做的活动以及这些活动的执行顺序. --->uml中有两个层面的活动图,一种用于描述用例场景,叫[用例活动图],另一种用于描述对象交互,叫[对象活动图]. --->在面向对象的眼中是没有业

动态游标(例如表名作为参数)以及动态SQL分析

表名作为参数的动态游标 DECLARE v_table_name VARCHAR2(30) := 'CUX_MES_WIP_BARCODE_MAP'; --l_rec SYS_REFCURSOR; TYPE t_data IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER; TYPE t_cur IS REF CURSOR; l_data t_data; l_rec t_cur; l_cur VARCHAR2(4000); v_fm_barcode

OPENERP 构建动态视图

来自:http://shine-it.net/index.php/topic,16142.0.html 在openerp展示界面通常是通过定义class的view(xml文件)来实现的. 有时这种方法不能支持用户自定义字段的需求,于是就可以通过重写fields_view_get(). read()来实现. 实例代码 # -*- coding: utf-8 -*- from openerp.osv import osv,fields from lxml import etree from open

Oracle 参数文件、v$parameter动态视图、OMF特性、启动

PFILE与SPFILE 1.  含义:PFILE是parameterfile的缩写,SPFILE是server parameter file的缩写,通过全称的字面含义,我们可以得到pfile和spfile都是oracle提供的参数文件,里面写着各种参数的初始值,比如Database Buffer的值为196M等,文件后缀名都是.ora: 2.  区别:spfile是oracle9i release2引进的新事物,在这之前oracle中只有pfile的概念.Pfile是一种静态参数文件,可以通过

Java 常用List集合使用场景分析

Java 常用List集合使用场景分析 过年前的最后一篇,本章通过介绍ArrayList,LinkedList,Vector,CopyOnWriteArrayList 底层实现原理和四个集合的区别.让你清楚明白,为什么工作中会常用ArrayList和CopyOnWriteArrayList?了解底层实现原理,我们可以学习到很多代码设计的思路,开阔自己的思维.本章通俗易懂,还在等什么,快来学习吧! 知识图解: 技术:ArrayList,LinkedList,Vector,CopyOnWriteAr