Reorg
当数据库里某个表中的记录变化量非常大时。须要在表上做REORG操作来优化性能。
值得注意的是,针对数据库对象的大量操作,如重复地删除表。存储过程。会引起系统表中数据的频繁改变。在这样的情况下,也要考虑对系统表进行REORG操作。
一个完整的REORG表的过程应该是由以下的步骤组成的:
RUNSTATS -> REORGCHK -> REORG -> RUNSTATS -> BIND或REBIND
reorg table
[db2inst1@test1 ~]$ db2 reorg table DB2INST1.ACT inplace allow write access
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTM0NzAxOTQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
生成脚本:
[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' "
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTM0NzAxOTQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">