Chinaunix首页 | 论坛 | 博客
  • 博客访问: 687926
  • 博文数量: 147
  • 博客积分: 5347
  • 博客等级: 大校
  • 技术积分: 1453
  • 用 户 组: 普通用户
  • 注册时间: 2005-06-06 11:11
文章分类

全部博文(147)

文章存档

2014年(4)

2012年(9)

2011年(5)

2010年(28)

2009年(21)

2008年(29)

2007年(15)

2006年(17)

2005年(19)

我的朋友

分类:

2010-04-15 14:37:44

今天把db2 reorg搞了一遍,有些许收获,同时也有些许疑问
经过测试发现:db2 reorg table分三个阶段  1---build  2—replace  3—index recreate (详细可以参见下面的测试步骤)
注:若表无索引只分两个阶段
第一阶段,使用表空间中空余空间(或指定表空间)临时生成一个表进行表的重组,即使中断也不会对原有表或索引产生影响;
第二阶段,也就是替换原表阶段是无法认为手工中断的,即使在此阶段发出了中断命令(CTRL+C)也对等此步骤完成后,索引未重创前才中断,此时会明确告诉用户索引未创建。(SQL1279W  Some indexes may not have been recreated.)
第三阶段,可以手工,同时明确告诉用户索引未创建。(SQL1279W  Some indexes may not have been recreated.)
另外我模拟了在reorg第二阶段时,数据库突然down机的情况这时如操作系统正常,则在reorg的操作窗口明确报告,reorg期间中断。
$ db2 reorg table db2inst1.test_table
SQL2216N  SQL error "-1224" occurred while reorganizing a database table or
its indexes.
若操作系统不正常或重新启动后,在进行数据库连接时自动做 recover 动作:
2010-03-11-15.18.03.060657+480 I152520A366        LEVEL: Warning
PID     : 553154               TID  : 1           PROC : db2agent (TEST) 0
INSTANCE: db2inst1             NODE : 000         DB   : TEST
APPHDL  : 0-7                  APPID: *LOCAL.db2inst1.100311071803
FUNCTION: DB2 UDB, base sys utilities, sqledint, probe:30
MESSAGE : Crash Recovery is needed.
2010-03-11-15.18.42.295735+480 I154571A394        LEVEL: Warning
PID     : 553154               TID  : 1           PROC : db2agent (TEST) 0
INSTANCE: db2inst1             NODE : 000         DB   : TEST
APPHDL  : 0-7                  APPID: *LOCAL.db2inst1.100311071803
FUNCTION: DB2 UDB, recovery manager, sqlpresr, probe:3170
MESSAGE : Crash recovery completed. Next LSN is 000000007F724DEC
我们有多种途径来检查reorg操作是否正常完成:
1、Reorg完成后,一方面可以通过reorg操作的日志来检查是否正常完成;
2、另外一方面也可以通过以下方法确认:
db2  “select * from table(snapshot_tbreorg(‘test’,-1)) as reorg_snapshot” >>/tmp/reorg_result.txt
查看结果以下两个字段查看reorg是否正常.
“ REORG_PHASE” 看是否为3 , 若为3表示三阶段都已处理;  (若无索引则为2)
“REORG_COMPLETION” 为0 代表正常完成(-1,代表中断或失败)
此处有疑问--
snapshot_xxx结果集中很多列不知道什么意思,查询了资料也没查询到相关说明,不知道哪位老大有此方面的资料,能否共享下,感谢先。

3、同时也可以查看db2diag.log日志文件,其中有reorg table failed 的报错信息
2010-03-11-14.47.26.424955+480 I131968A385        LEVEL: Warning
PID     : 417990               TID  : 1           PROC : db2agent (TEST) 0
INSTANCE: db2inst1             NODE : 000         DB   : TEST
APPHDL  : 0-7                  APPID: *LOCAL.db2inst1.100311061046
MESSAGE : Reorg table failed.
DATA #1 : String, 56 bytes
Table(2:2)=DB2INST1.TEST_TABLE, Flags=x01014091, IID=0, Temp=0
 
 
查询进度:
1\ 查看reorg进度
db2 get snapshot for tables on  ksdbs

[db2inst1@rh4-db2 ~]$ db2 get snapshot for tables on ksdbs
            Table Snapshot
First database connect timestamp     = 2010-04-14 08:56:57.524055
Last reset timestamp                 =
Snapshot timestamp                   = 2010-04-14 13:33:11.598333
Database name                        = KSDBS
Database path                        = /db2/db2inst1/NODE0000/SQL00001/
Input database alias                 = KSDBS
Number of accessed tables            = 2
Table List
 Table Schema        = SYSIBM
 Table Name          = SYSTABLES
 Table Type          = Catalog
 Data Object Pages   = 95
 Index Object Pages  = 46
 LOB Object pages    = 2112
 Rows Read           = Not Collected
 Rows Written        = 0
 Overflows           = 5
 Page Reorgs         = 0
 Table Schema        = KS
 Table Name          = HIS_FUND_STOCK_CHG
 Table Type          = User
 Data Object Pages   = 175
 Index Object Pages  = 62
 Rows Read           = Not Collected
 Rows Written        = 0
 Overflows           = 0
 Page Reorgs         = 0
 Table Reorg Information:
   Reorg Type        =
        Reclaiming
        Table Reorg
        Allow Read Access
        Recluster Via Table Scan
        Reorg Data Only
   Reorg Index       = 0
   Reorg Tablespace  = 3
   Start Time        = 2010-04-14 13:31:57.779723
   Reorg Phase       = 3 - Index Recreate
   Max Phase         = 3
   Phase Start Time  = 2010-04-14 13:31:58.459720
   Status            = Completed
   Current Counter   = 0
   Max Counter       = 0
   Completion        = 0
   End Time          = 2010-04-14 13:31:58.956485

2\ 查看reorg结果
db2 "select * from table(snapshot_tbreorg('ksdbs',-1)) as t"
注意:此结果只保留最后一次执行的reorg结果
阅读(25120) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-08-25 17:36:53

不错。 Column name Data type Description or corresponding monitor element SNAPSHOT_TIMESTAMP TIMESTAMP The date and time that the snapshot was taken. TABLE_NAME VARCHAR(128) table_name - Table name TABLE_SCHEMA VARCHAR(128) table_schema - Table schema name PAGE_REORGS BIGINT page_reorgs - Page reorganizations REORG_PHASE BIGINT reorg_phase - Table reorganize phase REORG_MAX_PHASE INTEGER reorg_max_phase - Maximum table reorganize phase REORG_CURRENT_COUNTER BIGINT reorg_current_