What is REORGCHK all about?
db2 REORGCHK on table SCHEMA.TABLE
Make sure RUNSTATS is up to date or tell it to take new STATS. REORGCHK needs current statistics!
db2 -x "CALL SYSPROC.REORGCHK_TB_STATS('T','SCHEMA.TABLE')"
Reduce I/O Cost - F1: 100 * OVERFLOW / CARD < 5 The total number of overflow records in the table should be less than %5
Reduce Storage Cost - F2: 100 * (Effective Space Utilization of Data Pages) > 70 There should be less than %30 free space in the table
Reduce Storage Cost - F3: 100 * (Required Pages / Total Pages) > 80 The number of pages that contains no rows at all should be less than %20 of the pages in the table
从各个方面来衡量是不是需要reorg
overflows的行数 vs 总行数
含有数据的页面的数量 vs 总的页面的数
占用数据的空间 vs 总的空间
Offline Table Reorg Phases
Dictionary Build
1. SORT
If an index is specified with the REORG TABLE command, or if a clustering index is defined on the table, the rows of the table are first sorted according to that index. If the INDEXSCAN option is specified, an index scan is used to sort the table, otherwise, a table scan sort is used. This phase only applies to a clustering REORG. Space reclaiming reorganizations begin at the build phase.
2. BUILD
In this phase, a reorganized copy of the entire table is build, either in the table space that the table being reorganized resides, or in a temporary table space specified with the REORG command.
3. REPLACE
In this phase, the original table object is replaced by either copying back from the temporary table space, or by pointing to the newly built object within the table space of the table being reorganized.
4. RECREATE ALL INDEXES
All indexes defined on the table are recreated
Advantages
Fastest method
Perfectly clustered data
Indexes rebuilt automatically O
ption to use Temp space to lower space requirement.
Disadvantages
Limited access to tables. (read only during part of the process)
Space required for copy of the table to be built
Little control of the process once it starts.
You have two command two monitor the reorg on db2 V9:
db2pd -d -reorg
or
db2 "select * from SYSIBMADM.SNAPTAB_REORG"
or
SELECT SUBSTR(TABNAME, 1, 15) AS TAB_NAME, SUBSTR(TABSCHEMA, 1, 15) AS TAB_SCHEMA, REORG_PHASE, SUBSTR(REORG_TYPE, 1, 20) AS REORG_TYPE, REORG_STATUS, REORG_COMPLETION, DBPARTITIONNUM FROM SYSIBMADM.SNAPTAB_REORG ORDER BY DBPARTITIONNUM
--REORG Table Analysis?
--Database History File
SELECT substr(tabname, 1, 7) AS tabname
,operation
,operationtype
,objecttype
,start_time
,end_time
FROM SYSIBMADM.DB_HISTORY
WHERE operation = 'G'
--SYSIBMADM.SNAPTAB_REORG
SELECT SUBSTR(TABNAME, 1, 15) AS TAB_NAME
,SUBSTR(TABSCHEMA, 1, 15) AS TAB_SCHEMA
,REORG_PHASE
,SUBSTR(REORG_TYPE, 1, 20) AS REORG_TYPE
,REORG_STATUS
,REORG_COMPLETION
,DBPARTITIONNUM
FROM SYSIBMADM.SNAPTAB_REORG
ORDER BY DBPARTITIONNUM
--Table Snapshot
db2 reorg table staff3 index i3
db2 get snapshot for tables on SAMPLE
Online Table Reorg Analysis? Monitoring
// Recluster data, allowing write access always
REORG TABLE t1 INDEX i1 INPLACE ALLOW WRITE ACCESS NOTRUNCATE TABLE
GET SNAPSHOT FOR TABLES ON // Query status
Online Table REORG – Which DB Partition had the Error?
.nfy
History File
db2pd -db xxxxx -reorg