查看: 7778|回复: 4

DB2如何获取完整的SQL语句

[复制链接]
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:282011新春纪念徽章
日期:2011-02-18 11:43:34
跳转到指定楼层
1#
发表于 2010-9-9 11:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用如下语句获取到一些很耗时的语句,但是stmt_text是截断的,请问你我如何获取到这些语句的完成语句?
select total_exec_time,num_executions,total_exec_time/num_executions time_per_exec,stmt_text from table(snapshot_dyn_sql('',-1)) A
where num_executions>0
order by total_exec_time/num_executions desc
fetch first 20 rows only;

谢谢
论坛徽章:
44
青年奥林匹克运动会-自行车
日期:2014-09-12 22:37:432012新春纪念徽章
日期:2012-02-13 15:12:092012新春纪念徽章
日期:2012-02-13 15:12:09咸鸭蛋
日期:2012-01-08 14:47:322012新春纪念徽章
日期:2012-01-04 11:50:44ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15迷宫蛋
日期:2011-08-14 17:30:33双黄蛋
日期:2011-05-28 20:32:46紫蛋头
日期:2011-05-18 20:41:51现任管理团队成员
日期:2011-05-07 01:45:08
2#
发表于 2010-9-9 11:57 | 只看该作者
原帖由 newcomer1981 于 2010-9-9 11:21 发表
我用如下语句获取到一些很耗时的语句,但是stmt_text是截断的,请问你我如何获取到这些语句的完成语句?
select total_exec_time,num_executions,total_exec_time/num_executions time_per_exec,stmt_text from table(snapshot_dyn_sql('',-1)) A
where num_executions>0
order by total_exec_time/num_executions desc
fetch first 20 rows only;

谢谢


怎么会呢?!
STMT_TEXT CLOB(16M)1 stmt_text - SQL statement text  
这个字段是10MB大小的CLOB字段,还放不下你的SQL? please double check

使用道具 举报

回复
论坛徽章:
512
2012新春纪念徽章
日期:2012-01-04 11:53:54ITPUB十周年纪念徽章
日期:2011-11-01 16:23:26股神
日期:2012-01-05 10:29:02天枰座
日期:2015-09-16 09:05:30指数菠菜纪念章
日期:2015-07-01 16:40:43喜羊羊
日期:2015-06-30 09:06:18指数菠菜纪念章
日期:2015-04-02 09:22:462015年新春福章
日期:2015-03-06 11:58:18懒羊羊
日期:2015-03-04 14:52:11指数菠菜纪念章
日期:2015-01-04 11:09:18
3#
发表于 2010-9-11 12:46 | 只看该作者
会不会用的查询客户端,例如Quest Central会限制返回字段的宽度只有50个字节,超过的都会被截断

使用道具 举报

回复
论坛徽章:
3
ITPUB8周年纪念徽章
日期:2009-10-09 16:30:262011新春纪念徽章
日期:2011-01-04 10:38:212011新春纪念徽章
日期:2011-02-24 10:56:39
4#
发表于 2011-2-24 13:33 | 只看该作者

看看这个


  1. #监控执行成本最高的sql语句
  2. select agent_id,rows_selected,rows_read from sysibmadm.snapappl fetch first 10 rows only;

  3. #监控运行最长的sql语句
  4. select substr(appl_name,1,15) as Appl_name,elapsed_time_min as "Elapsed Min.",appl_status as "Status ",substr(authid,1,10) as auth_id,
  5. substr(inbound_comm_address,1,15) as "IP Address",substr(stmt_text,1,30) as "SQL Statement"
  6. from sysibmadm.long_running_sql order by 2 desc;

  7. select * from sysibmadm.long_running_sql order by 2 desc;

  8. #监控sql准备和预编译时间最长的sql语句
  9. average_execution_time_s sql语句平均执行时间
  10. prep_time_ms   最长的sql预编译时间
  11. prep_time_precent 预编译时间占整个执行时间的百分比
  12. select num_executions,average_execution_time_s,prep_time_ms,prep_time_precent,substr(stmt_text,1,40) as "SQL_Text"
  13. from sysibmadm.query_prep_cost where average_execution_time_s>0 order by prep_time_precent desc;

  14. #监控执行次数最多的sql语句
  15. Select num_executions "Num Execs",average_execution_time_s as "Avg Time(sec)",stmt_sorts as "Num Sorts",sorts_per_execution as "Sorts Per Stmt",
  16. substr(stmt_text,1,35) as "SQL Stmt" from sysibmadm.top_dynamic_sql where num_executions>0 order by 1 desc fetch first 5 rows only;

  17. Select num_executions "Num Execs",average_execution_time_s as "Avg Time(sec)",stmt_sorts as "Num Sorts",sorts_per_execution as "Sorts Per Stmt",
  18. substr(stmt_text,1,35) as "SQL Stmt" from sysibmadm.top_dynamic_sql where num_executions>0 order by 2 desc fetch first 5 rows only;


  19. #监控排序次数最多的sql语句
  20. select stmt_sorts,sorts_per_execution,substr(stmt_text,1,60) as stmt_text from top_dynamic_sql order by stmt_sorts fetch first 5 rows only;
复制代码

使用道具 举报

回复
论坛徽章:
1
ITPUB知识分享者
日期:2011-04-27 17:19:08
5#
发表于 2011-4-28 18:46 | 只看该作者
用表函数mon_get_pkg_cache_stmt('D', NULL, NULL, -2)试试。 e.g.
db2 "select * from table(mon_get_pkg_cache_stmt('D', NULL, NULL, -2)) as T order by total_cpu_time fetch first 10 rows only"
(查看消耗CPU时间最多的10个静态SQL语句。将参数‘D’改为‘S’,可以得到对应动态SQL语句的结果,改为NULL则得到对应所有SQL语句的结果)

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表