Friday 18 November 2011

Sample Shell Script 2: Find the nzreclaim candidate for any database

#!/bin/sh
# ./nzDeleteRecPercentage.sh dbname
############################################################################
# Name: nzDeleteRecPercentage.sh
# Desc: Get the list of tables of a database for which at least one deleted
# record exists in the form of percentage. We can use this percentage to
# choose candidate for nzreclaim/GROOM table operation
#
# Change Log
# Ver   Date            Author          Comment
# ---   -----------     -------------   ----------------------------------------
# 1.0   MM/DD/YYYY      SD              Creation
#
#############################################################################

#LOGDIR=/home/nz_training_user14/sankar
#LOGFILE="${LOGDIR}/nzDeleteRecPercentage.log"
#ERRFILE="${LOGDIR}/nzDeleteRecPercentage.err"


DATABASENAME=${1}
#echo "Database: ${DATABASENAME}"


TABLES=`nzsql -u UserName -pw Password -db ${DATABASENAME} -t -c "SELECT TABLENAME FROM _V_TABLE;"`

#echo ${TABLES}

for TABLENAME in ${TABLES}
do
    DELETECOUNT=`nzsql -u UserName -pw Password -db ${DATABASENAME} -t -c "set show_deleted_records=true; SELECT COUNT(1) FROM ${TABLENAME} WHERE deletexid<>0;"`

   
    if [ ${DELETECOUNT} -gt 0 ]
    then
        TOTALCOUNT=`nzsql -u UserName -pw Password -db ${DATABASENAME} -t -c "SELECT COUNT(1) FROM ${TABLENAME};"`
        PERCENTAGE=`echo "scale=2;($DELETECOUNT*100/($TOTALCOUNT+$DELETECOUNT))" | bc`
        echo "${TABLENAME} has ${PERCENTAGE}% deleted records "
    fi
done

No comments:

Post a Comment