设为首页 收藏本站
查看: 1280|回复: 0

[经验分享] DB2 runstats和reorg操作

[复制链接]

尚未签到

发表于 2016-11-18 08:25:08 | 显示全部楼层 |阅读模式
[db2inst1@xifenfei ~]$ db2 connect to xff

   Database Connection Information

Database server        = DB2/LINUX 9.5.9
SQL authorization ID   = DB2INST1
Local database alias   = XFF

[db2inst1@xifenfei ~]$ db2 list tables

Table/View                      Schema          Type  Creation time            
------------------------------- --------------- ----- --------------------------
T_01XFF                         DB2INST1        T     2012-04-11-18.23.05.723478
T_02XFF                         DB2INST1        T     2012-04-11-18.30.26.639326
T_03XFF                         DB2INST1        T     2012-04-11-21.33.12.479480

  3 record(s) selected.

[db2inst1@xifenfei ~]$ db2 "select STATS_TIME from syscat.tables where tabname in('T_01XFF','T_02XFF','T_03XFF')"

STATS_TIME               
--------------------------
2012-04-12-04.35.07.539790
2012-04-11-19.55.12.023748
2012-04-11-22.20.07.016905

  3 record(s) selected.

--收集表和索引统计信息,包括数据分布
[db2inst1@xifenfei ~]$ db2 "runstats on table db2inst1.t_01xff on all columns
with distribution and detailed indexes all"
DB20000I  The RUNSTATS command completed successfully.
[db2inst1@xifenfei ~]$ db2 "select STATS_TIME from syscat.tables where tabname in('T_01XFF')"

STATS_TIME               
--------------------------
2012-04-28-23.43.23.904759

  1 record(s) selected.

--收集索引统计信息,如果表没有被收集,也会同时对表收集统计信息,对不会收集数据分布信息
[db2inst1@xifenfei ~]$ db2 "runstats on table db2inst1.t_02xff for  indexes all"
DB20000I  The RUNSTATS command completed successfully.


[db2inst1@xifenfei ~]$ db2 "select STATS_TIME from syscat.tables where tabname in('T_01XFF','T_02XFF')"

STATS_TIME               
--------------------------
2012-04-28-23.43.23.904759
2012-04-28-23.44.39.762858

  2 record(s) selected.  db2 reorg操作


--删除部分表数据
[db2inst1@xifenfei ~]$ db2 "delete from t_01xff"
DB20000I  The SQL command completed successfully.
[db2inst1@xifenfei ~]$ db2 "delete from t_03xff"
DB20000I  The SQL command completed successfully.

--reorgchk检查是否需要进行reorg
[db2inst1@xifenfei ~]$ db2 reorgchk on schema db2inst1

Doing RUNSTATS ....


Table statistics:

F1: 100 * OVERFLOW / CARD < 5
F2: 100 * (Effective Space Utilization of Data Pages) > 70
F3: 100 * (Required Pages / Total Pages) > 80

SCHEMA.NAME                     CARD     OV     NP     FP ACTBLK    TSIZE  F1  F2  F3 REORG
----------------------------------------------------------------------------------------
Table: DB2INST1.T_01XFF
                                   0      0      0     42      -        0   0   0   0 -**
Table: DB2INST1.T_02XFF
                                 371      0     42     42      -   152110   0 100 100 ---
Table: DB2INST1.T_03XFF
                                   0      0      0     83      -        0   0   0   0 -**
----------------------------------------------------------------------------------------

Index statistics:

F4: CLUSTERRATIO or normalized CLUSTERFACTOR > 80
F5: 100 * (Space used on leaf pages / Space available on non-empty leaf pages) > MIN(50, (100 - PCTFREE))
F6: (100 - PCTFREE) * (Amount of space available in an index with one less level / Amount of space required for all keys) < 100
F7: 100 * (Number of pseudo-deleted RIDs / Total number of RIDs) < 20
F8: 100 * (Number of pseudo-empty leaf pages / Total number of leaf pages) < 20

SCHEMA.NAME                 INDCARD  LEAF ELEAF LVLS  NDEL    KEYS LEAF_RECSIZE NLEAF_RECSIZE LEAF_PAGE_OVERHEAD NLEAF_PAGE_OVERHEAD  F4  F5  F6  F7  F8 REORG  
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Table: DB2INST1.T_01XFF
Index: DB2INST1.I_T_01XFF
                                  0     3     3    2     0       0            2             2                822                 822 100   0   -   0 100 ----*
--------------------------------------------------------------------------------------------------------------------------------------------------------------

CLUSTERRATIO or normalized CLUSTERFACTOR (F4) will indicate REORG is necessary
for indexes that are not in the same sequence as the base table. When multiple
indexes are defined on a table, one or more indexes may be flagged as needing
REORG.  Specify the most important index for REORG sequencing.

Tables defined using the ORGANIZE BY clause and the corresponding dimension
indexes have a '*' suffix to their names. The cardinality of a dimension index
is equal to the Active blocks statistic of the table.

--离线reorg index
[db2inst1@xifenfei ~]$ db2 reorg table db2inst1.t_01xff index DB2INST1.I_T_01XFF allow read access
DB20000I  The REORG command completed successfully.

--在线reorg table
[db2inst1@xifenfei ~]$ db2 reorg table db2inst1.t_01xff inplace allow write access
DB20000I  The REORG command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

[db2inst1@xifenfei ~]$ db2 reorg table db2inst1.t_03xff inplace allow write access
DB20000I  The REORG command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

--证明异步操作完成
[db2inst1@xifenfei ~]$ ps -ef|grep db2reo
db2inst1  1496  1311  0 00:24 pts/1    00:00:00 grep db2reo

--检查reorg操作结果
[db2inst1@xifenfei ~]$ db2 reorgchk on schema db2inst1

Doing RUNSTATS ....


Table statistics:

F1: 100 * OVERFLOW / CARD < 5
F2: 100 * (Effective Space Utilization of Data Pages) > 70
F3: 100 * (Required Pages / Total Pages) > 80

SCHEMA.NAME                     CARD     OV     NP     FP ACTBLK    TSIZE  F1  F2  F3 REORG
----------------------------------------------------------------------------------------
Table: DB2INST1.T_01XFF
                                   0      0      0      1      -        0   0   -   0 ---
Table: DB2INST1.T_02XFF
                                 371      0     42     42      -   152110   0 100 100 ---
Table: DB2INST1.T_03XFF
                                   0      0      0      1      -        0   0   -   0 ---
----------------------------------------------------------------------------------------

Index statistics:

F4: CLUSTERRATIO or normalized CLUSTERFACTOR > 80
F5: 100 * (Space used on leaf pages / Space available on non-empty leaf pages) > MIN(50, (100 - PCTFREE))
F6: (100 - PCTFREE) * (Amount of space available in an index with one less level / Amount of space required for all keys) < 100
F7: 100 * (Number of pseudo-deleted RIDs / Total number of RIDs) < 20
F8: 100 * (Number of pseudo-empty leaf pages / Total number of leaf pages) < 20

SCHEMA.NAME                 INDCARD  LEAF ELEAF LVLS  NDEL    KEYS LEAF_RECSIZE NLEAF_RECSIZE LEAF_PAGE_OVERHEAD NLEAF_PAGE_OVERHEAD  F4  F5  F6  F7  F8 REORG  
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Table: DB2INST1.T_01XFF
Index: DB2INST1.I_T_01XFF
                                  0     1     0    1     0       0            2             2                822                 822 100   -   -   0   0 -----
--------------------------------------------------------------------------------------------------------------------------------------------------------------

CLUSTERRATIO or normalized CLUSTERFACTOR (F4) will indicate REORG is necessary
for indexes that are not in the same sequence as the base table. When multiple
indexes are defined on a table, one or more indexes may be flagged as needing
REORG.  Specify the most important index for REORG sequencing.

Tables defined using the ORGANIZE BY clause and the corresponding dimension
indexes have a '*' suffix to their names. The cardinality of a dimension index
is equal to the Active blocks statistic of the table.
Please refer to : http://www.xifenfei.com/3013.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-301886-1-1.html 上篇帖子: db2中的常用命令及使用方法 下篇帖子: db2备份数据库的几种方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表