Reorg

来源:互联网 发布:剑三正太捏脸数据截图 编辑:程序博客网 时间:2024/06/06 09:09

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' "



 

0 0
原创粉丝点击