一、db2监控动态SQL(快照监控)

db2示例用户登陆后,使用脚本语句db2 get snapshot for all on dbname>snap.out

也可以使用db2 get snapshot for dynamic SQL on dbname>snap.out,此语句是只记录上一语句中的部分

Tips:如果需要监控尽可能多的SQL语句,建议增加DBM配置参数


以下是动态SQL快照

Dynamic SQL Snapshot Result

 Database name                      = QINDB

 Database path                      = /db2home/db2inst1/db2inst1/NODE0000/SQL00002/
Number of executions = 3 --编译次数,为累加值
Number of compilations = 1 --SQL语句编译的最长时间
Worst preparation time (ms) = 87
Best preparation time (ms) = 87
Internal rows deleted = Not Collected
Internal rows inserted = Not Collected
Rows read = Not Collected
Internal rows updated = Not Collected
Rows written = Not Collected
Statement sorts = Not Collected
Statement sort overflows = Not Collected
Total sort time = Not Collected
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index physical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Buffer pool xda logical reads = Not Collected
Buffer pool xda physical reads = Not Collected
Buffer pool temporary xda logical reads = Not Collected
Buffer pool temporary xda physical reads = Not Collected
Total execution time (sec.microsec)= Not Collected --SQL语句的总执行时间
Total user cpu time (sec.microsec) = Not Collected
Total system cpu time (sec.microsec)= Not Collected
Total statistic fabrication time (milliseconds) = Not Collected
Total synchronous runstats time (milliseconds) = Not Collected
Statement text = select * from len.cust_info where cust_id like '%09' --SQL语句文本

Number of executetions:可以帮助找到最优的那些重要语句,它对于帮助计算语句的平均执行时间也很有用。

Rows read :可以帮助识别读取行数最多的动态SQL语句,如果读取行数最多,通常意味着进行全表扫描。

Total execution time:是将语句每次执行时间加起来得到的总时间,我们可以利用该时间除以Number of executrtions,可以得到平均执行时间。如果语句的平均执行时间很长,可能是因为表扫描或者出现锁等待。

基于上述使用语句db2 get snapshot for all on dbname生成的文本内容,我们可以使用grep对快照的输出内容执行搜索

例如:

<1> 识别是否存在死锁

grep -n "Deadlocks detected" snap.out |grep -v "= 0" |more

<2> 搜索执行最频繁的SQL语句

grep -n "Number of executions" snap.out | grep -v "= 0" | sort -k 6rn |more

<3> 查询总的执行时间

 grep -n "Total execution time" snap.out | grep -v "= 0.0"| sort -k 6nr| more

二、监控动态SQL(db2top)

使用db2top命令找出最频繁、最耗时的SQL(使用db2数据库用户登录)

db2top –d dbname

按D,进入到SQL监控界面(如果没开大写,可以使用shift+d)

按z,倒序排序

输入排序列的序号,从0开始

按L,输入SQL的序列号,查看SQL明细

以下为示例操作:

(1)db2inst1@Linux:/qinys> db2top -d qindb

(2)按D进入

(3)按z倒序排序,此处我输入3,表示按照执行时间排序

(4)按L输入SQL序列号,查看SQL详细

从上图我们就可以查看SQL详细了

【DB2】监控动态SQL语句的更多相关文章

  1. Ibatis.Net 动态SQL语句学习(六)

    在学习动态SQL语句之前,首先必须对条件查询有一定了解,先来学习如何向IBatis.Net的映射文件里传入参数吧. 一.条件查询 1.传递单个参数 如根据Id查询: <select id=&qu ...

  2. 动态sql语句、逆向工程(generator)、分页助手(pagehelper)

    1.动态sql语句 if if where 配合使用 <select id="selectByWhere" resultType="com.alibaba.wlq. ...

  3. MySQL存储过程动态SQL语句的生成

    用Mysql存储过程来完成动态SQL语句,使用存储过程有很好的执行效率: 现在有要求如下:根据输入的年份.国家.节假日类型查询一个节假日,我们可以使用一般的SQL语句嵌入到Java代码中,但是执行效率 ...

  4. 动态sql语句基本语法--Exec与Exec sp_executesql 的区别

    http://www.cnblogs.com/goody9807/archive/2010/10/19/1855697.html 动态sql语句基本语法 1   :普通SQL语句可以用Exec执行   ...

  5. mybatis实战教程(mybatis in action)之八:mybatis 动态sql语句

    mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类:1. if 语句 (简单的条件判断)2. c ...

  6. MyBatis学习(三)、动态SQL语句

    三.动态SQL语句 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Orac ...

  7. 三、动态SQL语句

    //备注:该博客引自:http://limingnihao.iteye.com/blog/106076 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空, ...

  8. IBatis.net动态SQL语句

    在学习动态SQL语句之前,首先必须对条件查询有一定了解,先来学习如何向IBatis.Net的映射文件里传入参数. 一.条件查询 1.传递单个参数 如根据Id查询: <select id=&quo ...

  9. 存储过程中执行动态Sql语句

    MSSQL为我们提供了两种动态执行SQL语句的命令,分别是EXEC和sp_executesql;通常,sp_executesql则更具有优势,它提供了输入输出接口,而EXEC没有.还有一个最大的好处就 ...

随机推荐

  1. SVG.js 元素操作整理(一)

    一.属性操作Attributes var draw = SVG('svg1').size(300, 300); //attr() 属性操作 //设置属性的值 var rect = draw.rect( ...

  2. 聚类:层次聚类、基于划分的聚类(k-means)、基于密度的聚类、基于模型的聚类

    一.层次聚类 1.层次聚类的原理及分类 1)层次法(Hierarchicalmethods)先计算样本之间的距离.每次将距离最近的点合并到同一个类.然后,再计算类与类之间的距离,将距离最近的类合并为一 ...

  3. api重复引用导致的诡异问题排查

    api重复引用导致的诡异问题排查 最近一个项目上线前开发环境.测试环境都能正常打包并运行.然而到了准生产环境和生产环境则报一些诡异的错误信息: [INFO] --------------------- ...

  4. 6.2 dubbo在spring中自定义xml标签源码解析

    在6.1 如何在spring中自定义xml标签中我们看到了在spring中自定义xml标签的方式.dubbo也是这样来实现的. 一 META_INF/dubbo.xsd 比较长,只列出<dubb ...

  5. 升级项目到Vs2010,编译时出现:MSB6006: “LC.exe”已退出,解决方法

    最近装了Vs2010 准备把一些项目,升级到.Net 4.0 在编译时,总是出现 MSB6006: “LC.exe”已退出 的错误.很是郁闷.刚开始以为是第三方控件的,去掉了,也不行.后来在网上找了一 ...

  6. Downloading files from a server to client, using ASP.Net, when file size is too big for MemoryStream using Generic Handlers (ashx)

    Currently, I was trying to write an ASP.Net application that involved a user clicking a ASP.Net butt ...

  7. [leetcode]Restore IP Addresses @ Python

    原题地址:https://oj.leetcode.com/problems/restore-ip-addresses/ 题意: Given a string containing only digit ...

  8. maskrcnn_benchmark代码分析(3)

    数据结构 数据加载 数据后处理

  9. iOS开发-UISwipeGestureRecognizer滑动手势

    滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧: UISwipeGestureRecogni ...

  10. Spark简介及其在ubuntu下的安装使用

    转:http://blog.csdn.net/pelick/article/details/9888311 Spark概述 Spark是一种与 Hadoop 相似的开源集群计算环境,在性能和迭代计算上 ...