0% found this document useful (0 votes)
337 views2 pages

Db2 Reorg Help

This document provides information on checking if a DB2 table needs reorganization and performing reorganization. It includes the syntax for running reorgchk to check table statistics, definitions of metrics checked by reorgchk, and the syntax for performing an online reorganization with runstats before and after. Monitoring of active reorgs and finding references on reorg best practices are also covered.

Uploaded by

koool_king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
337 views2 pages

Db2 Reorg Help

This document provides information on checking if a DB2 table needs reorganization and performing reorganization. It includes the syntax for running reorgchk to check table statistics, definitions of metrics checked by reorgchk, and the syntax for performing an online reorganization with runstats before and after. Monitoring of active reorgs and finding references on reorg best practices are also covered.

Uploaded by

koool_king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

The simplest form of the reorgchk command is this:

db2 "reorgchk current statistics on table all" >reorgchk.out


For F1, this is a handy query to find tables that need reorgs:
Hint : Formula F1 looks to ensure that 5% or less of the total rows in the table
are overflows
select substr(tabschema,1,18) as tabschema,
substr(tabname,1,30) as tabname,
card,
overflow,
case when card > 0
then decimal(100*(float(overflow)/float(card)),10,2)
else -1
end as F1
from syscat.tables
where overflow >0 with ur

for F2 :
F2 is described in the reorgchk header as:
100 * (Effective Space Utilization of Data Pages) > 70

F3
F3 is described in the reogchk header as:
100 * (Required Pages / Total Pages) > 80
Basically DB2 is checking to make sure that the total pages in the table is not
more than 20% higher than the required number of pages.
The sql calculation is much easier here, again use this SQL at your own risk:
select substr(tabschema,1,18) as tabschema,
substr(tabname,1,30) as tabname,
npages,
fpages,
case
when fpages >0 then decimal(100 * (float(npages)/float(fpages)),5,2)
else -1
end as F3
from syscat.tables
where type='T'
and npages >1
and fpages >1
with ur

TO check if a table needs reorg


db2 "call REORGCHK_TB_STATS('T','SYSIBM.SYSCOLUMNS')"
call REORGCHK_TB_STATS('T','ALL')

The syntax for an online reorg looks like this:


> db2 "reorg table STAGLOG index SQL120615064145450 inplace allow write access"
You can monitor its progress by using db2pd:
db2pd -d wc037d01 -reorg |grep STAGLOG

remember that you should do a runstats both before AND after the reorg. My favo
rite runstats syntax is:
db2 runstats on table STAGLOG with distribution and detailed indexes all

To find any active inplace (online) reorgs that you have running, use:
db2 "select snapshot_timestamp, reorg_start, substr(table_name,1,18) as table_na
me, REORG_CURRENT_COUNTER, REORG_MAX_COUNTER, REORG_TYPE, REORG_STATUS from tabl
e(SNAPSHOT_TBREORG('$db_name', -1)) as tab_reorg where reorg_status=1"
You can also get the same information from a table snapshot:
> db2 get snapshot for tables on dbname

select substr(a.tabname,1,30) as TABNAME,


a.rows_read as RowsRead,
(a.rows_read / (b.commit_sql_stmts + b.rollback_sql_stmts + 1)) as TBRRTX,
(b.commit_sql_stmts + b.rollback_sql_stmts) as TXCNT
from sysibmadm.snaptab a, sysibmadm.snapdb b
where a.dbpartitionnum = b.dbpartitionnum
and b.db_name = 'DBNAME'
order by a.rows_read desc;

Reference :
http://db2commerce.com/2012/02/22/issue-with-online-reorgs-on-unformatted-event-
monitor-tables/
http://db2commerce.com/2012/07/12/how-to-delete-data-from-a-db2-table-and-releas
e-disk-space/
http://db2commerce.com/2014/06/02/how-to-tell-when-a-table-reorg-is-needed/
http://db2commerce.com/2013/05/09/when-is-a-reorg-really-online/
http://db2commerce.com/2016/09/27/embers-best-practices-for-runstats-and-reorgs/
http://www.dbisoftware.com/blog/db2_performance.php?id=116

You might also like