Reorgchk:重组检查,是否需要重组。
判断表或索引是否需要重组,有2种方法:
1.通过reorgchk工具
reorgchk工具利用8个公式(3个表公式,5个索引公式),如果表统计结果F1,F2或F3标记为*,则改表需要重组。如果索引统计结果F4-F8有*标记,则索引需要重组。
db2 reorgchk on schema SYSTOOLS
Table statistics:
F1: * OVERFLOW / CARD <
F2: * (Effective Space Utilization of Data Pages) >
F3: * (Required Pages / Total Pages) >
Index statistics:
F4: CLUSTERRATIO or normalized CLUSTERFACTOR >
F5: * (Space used on leaf pages / Space available on non-empty leaf pages) > MIN(, ( - PCTFREE))
F6: ( - PCTFREE) * (Amount of space available in an index with one less level / Amount of space required for all keys) <
F7: * (Number of pseudo-deleted RIDs / Total number of RIDs) <
F8: * (Number of pseudo-empty leaf pages / Total number of leaf pages) <
2.通过sysibmadm.snaptab管理视图(只能检查表,索引的检查仍需要reorgchk)。(需要打开实例监控器开关 update dbm cfg using dft_mon_table on,重启实例生效)
如果发现overflow_access与rows_read比例高于3%,则需要对表进行重组。
db2 "select substr(TABNAME,1,18) as TABNAME,ROWS_READ,OVERFLOW_ACCESSES from sysibmadm.snaptab where (ROWS_READ>999) and ((OVERFLOW_ACCESSES*100)/(ROWS_READ+1)>3)" TABNAME ROWS_READ OVERFLOW_ACCESSES
------------------ -------------------- --------------------
T1 10004 3864
对所有表和索引执行reorgchk:
db2 reorgchk current statistics on table all
调用函数对所有表或索引执行reorgchk:
db2 "call SYSPROC.REORGCHK_TB_STATS(‘T‘,‘ALL‘)"| grep "*" | awk ‘{print $, $}‘ > reorgchk.out
db2 "call SYSPROC.REORGCHK_IX_STATS(‘T‘,‘ALL‘)"| grep "*" | awk ‘{print $, $}‘ >> reorgchk.out
------------------------------------------------------------------
reorg:重组,减少表和索引在物理存储上的碎片。
reorg重组分为表重组和索引重组。表重组支持:离线重组和在线重组。
离线表重组:
也称classic reorg,支持allow read access(默认选项),表示重组时其他应用可以读取数据。allow no access选项,表示重组过程中不允许访问改表。
离线表重粗采用影子拷贝方法,即创建一份原始数据的副本,在影子拷贝中进行数据reorg,reorg结束后替换源表数据。默认情况下,数据拷贝会在原表空间进行,也可以指定USE选项,在指定临时表空间进行。reorg过程中,会记录事务日志,当出现异常时可以通过日志进行恢复。离线reorg最多包含4个阶段:
a.scan-sort:根据reorg指定的索引对表数据进行扫描,排序 (如果没指定索引,表数据重组时不关心顺序)
b.build:根据第一阶段的结果进行表数据构建
c.replace:用于新数据替换原有数据
d.index rebuild:基于新数据,重建索引
可以用多种方式检查reorg是否完成:
1.通过sysibmadm.snaptab检查(要求dft_mon_table实例监控器开关打开)
db2 "select substr(tabname,1,15) as tabname,substr(tabschema,1,15) as tabschema,substr(reorg_type,1,50) as reorg_type,reorg_status,reorg_completion,dbpartitionnum from sysibmadm.snaptab_reorg" TABNAME TABSCHEMA REORG_TYPE REORG_STATUS REORG_COMPLETION DBPARTITIONNUM
--------------- --------------- -------------------------------------------------- ------------ ---------------- --------------
STAFF DB2INST2 RECLUSTER+OFFLINE+ALLOW_READ+TABLESCAN+DATAONLY COMPLETED SUCCESS 0
2.通过db2 get snapshot for tables on sample进行reorg监控:
Reorg Index =
Reorg Tablespace =
Start Time = // ::32.574580
Reorg Phase = - Index Recreate
Max Phase =
Phase Start Time = // ::33.026445
Status = Completed
Current Counter =
Max Counter =
Completion =
End Time = // ::33.315408
3.通过db2pd reorg选项获得当前正在执行和近期完成的重组信息:
db2pd -d sample -reorg
Database Partition -- Database SAMPLE -- Active -- Up days :: -- Date ---12.28.09.413756
Table Reorg Information:
Address TbspaceID TableID PartID MasterTbs MasterTab TableName Type IndexID TempSpaceID
0x00007F98399BA328 n/a n/a n/a STAFF Offline
Table Reorg Stats:
Address TableName Start End PhaseStart MaxPhase Phase CurCount MaxCount Status Completion
0x00007F98399BA328 STAFF // :: // :: // :: IdxRecreat Done
4.通过list history reorg all for sample获得表或索引重组信息:
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
G T F S0000001.LOG S0000002.LOG
----------------------------------------------------------------------------
Table: "DB2INST2"."STAFF"
----------------------------------------------------------------------------
Comment: REORG INDEX USE
Start Time:
End Time:
Status: A
----------------------------------------------------------------------------
EID: