设为首页 加入收藏

TOP

db2索引优化 (二)
2014-11-24 01:44:58 来源: 作者: 【 】 浏览:7
Tags:db2 索引 优化
决于 sql 语句缓存的当前内容。调用 data studio 时未驻留在缓存中的内容将未被分析。因此,当使用 sql 语句缓存作为输入时,应该在当天的不同时间点运行 design advisor,以计算更大范围的 sql 语句。


回页首

db2pd 实用程序

db2pd 实用程序通常用于问题诊断和监控,但也可用于查询关于数据库活动的信息。使用 db2pd 能够获得的信息之一是:自从数据库活动之后索引被访问的次数。清单 7 显示了如何使用 db2pd 实用程序为数据库中的所有表上的索引获取该信息。

清单 7. 使用 db2pd 实用程序查询表和索引的度量指标
db2pd -db sample -tcbstats all -file db2pd_tab_all.txt

以上调用 db2pd 的选项包含以下含义:
-db 数据库名
-tcbstats all 显示所有表和索引度量指标
-file 输出文件

如果您想要限制 db2pd 实用程序的输出,让它仅显示某些表及其索引,那么使用 -tcbstats 选项指定表空间 id 和表 id。为此,您首先需要在 syscat.tables 目录视图上执行 select 语句来确定表空间 id 和表 id,如清单 8 所示。

清单 8. 查询数据库目录以确定表的表空间 id 和表 id
db2 "select tbspaceid, tableid
from syscat.tables
where tabschema = 'fechner' and tabname = 'department'"

清单 9 显示了来自类似于以上的表空间 id 和表 id 查询的样例结果。

清单 9. 表空间 id 和表 id 查询的结果集
tbspaceid tableid
--------- -------
2 5

1 record(s) selected.

在确定您需要查询的表的表空间 id 和表 id 之后,您可以将 db2pd 输出仅限制到该表。为此,您可以在 -tcbstats 选项之后包含 tbspaceid 和 tableid 子选项,如清单 10 所示。

清单 10. 将 db2pd -tcbstats 输出限制到指定的表
db2pd -db sample -tcbstats all tbspaceid=2 tableid=5 -file db2pd_tab_dept.txt

清单 11 显示了来自类似于以上的 db2pd 查询的样例结果集。

清单 11. db2pd 实用程序显示的索引度量指标
database partition 0 -- database sample -- active -- up 0 days 00:20:34

tcb table information:
address tbspaceid tableid partid mastertbs mastertab tablename schemanm
objclass datasize lfsize lobsize xmlsize
0x797df2b8 2 5 n/a 2 5 department fechner
perm 1 0 0 0

tcb table stats:
address tablename schemanm scans udi rtsudi pgreorgs
nochgupdts reads fscrupdates inserts updates deletes ovflreads ovflcrtes
rowscomp rowsuncomp cclogreads storebytes bytessaved
0x797df2b8 department fechner 0 0 0 0
0 951 0 0 0 0 0 0
0 0 0 - -

tcb index information:
address inxtbspace objectid partid tbspaceid tableid mastertbs mastertab
tablename schemanm iid indexobjsize
0x797e0330 2 5 n/a 2 5 2 5
department fechner 3 8
0x797e0330 2 5 n/a 2 5 2 5
department fechner 2 8
0x797e0330 2 5 n/a 2 5 2 5
department fechner 1 8

tcb index stats:
address tablename iid partid emppgdel rootsplits bndrysplts pseuemptpg
empgmkdusd scans ixonlyscns keyupdates inclupdats nonbndspts pgallocs merges
pseudels delclean intnodspl
0x797e0330 department 3 n/a 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0
0x797e0330 department 2 n/a 0 0 0 0
0 678 0 0 0 0 1 0
0 0 0
0x797e0330 department 1 n/a 0 0 0 0
0 245 0 0 0 0 1 0
0 0 0

与索引使用相关的结果集部分包含在 tcb index stats 部分中。以上的样例输出显示了 department 表有 3 个索引。这些索引是通过索引 id 来表示的(iid 列),而不是索引名。scans 列显示了自数据库激活之后索引被访问的次数:
id 1 索引被访问了 245 次。
id 2 索引被访问了 678 次。
id 3 索引从未被访问过。

因为索引 id 3 从未被访问过,所以可以推断该索引为未使用或很少使用的索引。要获得 id 3 索引的名称,请使用 select 语句查询 syscat.indexes 目录视图,如清单 12 所示。

清单 12. 根据索引 id (iid) 查询数据库目

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇DB2中的sequence定义和使用 下一篇DB2 purescale vs Oracle RAC

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: