In DB2 LUW, Online reorg of table is Asynchronous which means if you trigger the command DB2 immediately gives message like "completed successfully" but it runs in the background.
Lets say you have a set of tables and would like to perform Online reorg on them using a script.
If you trigger a script it gets completed in few seconds however, DB2 runs them in the back ground (Read Online reorg of a table is Asynchronous). System may become IO bound.
Following function checks if online reorg on a table is completed and if it is, then reorg for next table gets triggered.
sysproc.snapshot_tbreorg - Table function being used
Reorg_status = 4 <if online reorg is completed>
online_reorg()
{
unset PID
echo "."
echo "###Online Reorg started on ${TBNAME} at `date`"
db2 -v "reorg table ${SCHEMA}.${TBNAME} inplace allow write access" &
sleep 1
unset CHK
while true;do
CHK=`db2 -x "select REORG_STATUS from table(sysproc.snapshot_tbreorg('',-1))as t where table_schema in '${SCHEMA}' and table_name in '${TBNAME}'"`
if [ $CHK = 4 ];then
echo "###Online Reorg completed on ${TBNAME} at `date`"
break
else
sleep 2
fi
done
}
Hope this function helps you...
Thanks for reading.
No comments:
Post a Comment