Reorg

Reorg

数据库里某个表中的记录变化量非常大时。须要在表上做REORG操作来优化数据库性能。

值得注意的是,针对数据库对象的大量操作,如重复地删除表。存储过程。会引起系统表中数据的频繁改变。在这样的情况下,也要考虑对系统表进行REORG操作。

一个完整的REORG表的过程应该是由以下的步骤组成的:

RUNSTATS -> REORGCHK -> REORG -> RUNSTATS -> BINDREBIND

reorg table

[db2inst1@test1 ~]$ db2 reorg table DB2INST1.ACT inplace allow write access      

 

生成脚本:

[db2inst1@test1 ~]$ cat reorg.sh

#!/bin/sh

echo 'date=`date  +%Y-%m-%d`'

echo 'time=`date +%H:%M:%S`'

echo 'echo $date'

echo 'echo $time'

echo 'db2 connect to sample'

db2 connect to sample > /dev/null

echo "#=======reorg table==="

db2 -x "select  'db2 reorg table '||rtrim(tabschema)||'.'||tabname||' inplace allow write access'  from  sysstat.tables where TABSCHEMA='DB2INST1' "

echo "#=======reorg index==="

db2 -x "select  'db2 reorg indexes all for table '||rtrim(tabschema)||'.'||tabname||' allow read access'  from  sysstat.tables where TABSCHEMA='DB2INST1' "

echo "#=======runstats==="

db2 -x "select  'db2 runstats on table '||rtrim(tabschema)||'.'||tabname||' with distribution and indexes all'  from  sysstat.tables where TABSCHEMA='DB2INST1' "



原文地址:https://www.cnblogs.com/cxchanpin/p/6742823.html