#!/bin/bash
####################################################################
#
# 将db2数据库某用户下的所有表进行数据统计分析
# 使用:修改tableSchema值和dbName值
#
####################################################################
tableSchema="DB2ECIF"
dbName="ecifdb"
db2 connect to $dbName > /dev/null
# 如果上一条命令执行后的结束代码不是0则执行下面的命令
if [ $? -ne 0 ]
then
db2 -x "SELECT TABNAME FROM SYSCAT.TABLES WHERE TABSCHEMA="$tableSchema" ORDER BY NPAGES DESC" >tables.list
for i in 0 1 2 3 4 5 6 7 8 9
do
echo "db2 connect to "$dbName";" >runstats$i.sh
chmod 755 runstats$i.sh
done
count=1
while read line
do
last_digit=`echo $count | sed 's/\(.*\)\(.\)$/\2/'`
echo "db2 runstats on table "$tableSchema".${line} on all columns with distribution and detailed indexes all;" >>runstats$last_digit.sh
count=`expr $count + 1`
done < tab.list
for i in 0 1 2 3 4 5 6 7 8 9
do
nohup ./runstats$i.sh >runstats$i.log &
done
####################################################################
#
# 将db2数据库某用户下的所有表进行数据统计分析
# 使用:修改tableSchema值和dbName值
#
####################################################################
tableSchema="DB2ECIF"
dbName="ecifdb"
db2 connect to $dbName > /dev/null
# 如果上一条命令执行后的结束代码不是0则执行下面的命令
if [ $? -ne 0 ]
then
echo "Failed to connect to database, please contact the administrator."
exit 1;
db2 -x "SELECT TABNAME FROM SYSCAT.TABLES WHERE TABSCHEMA="$tableSchema" ORDER BY NPAGES DESC" >tables.list
for i in 0 1 2 3 4 5 6 7 8 9
do
echo "db2 connect to "$dbName";" >runstats$i.sh
chmod 755 runstats$i.sh
done
count=1
while read line
do
last_digit=`echo $count | sed 's/\(.*\)\(.\)$/\2/'`
echo "db2 runstats on table "$tableSchema".${line} on all columns with distribution and detailed indexes all;" >>runstats$last_digit.sh
count=`expr $count + 1`
done < tab.list
for i in 0 1 2 3 4 5 6 7 8 9
do
nohup ./runstats$i.sh >runstats$i.log &
done