You are on page 1of 2

#!

/bin/bash
. /prod_ora/oracle/product/19.3.0/PRODCDB_dbprd001.env
function PreChks
{

if [[ ! -e $ORACLE_HOME ]]; then


echo " "
echo "Error ::: Given ORACLE_HOME :: $ORACLE_HOME does not exist!!! "
echo " "
exit;
fi

LOGFILE=/tmp/main.log
echo "Task Start at `date` " > $LOGFILE
export MAIL_RECIPIENT_INFO='ppalyam@osidigital.com'
}

function get_objects
{

echo "#CHECK FOR DATABASE and Tables STATUS##">>"$LOGFILE"


DB_OPEN_MODE=`sqlplus -s / as sysdba <<EOF
alter session set container=CMPPROD;
set pagesize 0 feedback off verify off heading off echo off
select open_mode from v\\$database;
EOF`
echo "$DB_OPEN_MODE">>"$LOGFILE"

echo "Fetch Stale_Stats Data"


sqlplus -s / as sysdba <<EOF > /tmp/a.log
alter session set container=CMPPROD;
set pagesize 0 feedback off verify off heading off echo off
set linesize 300
select table_name, owner from dba_tab_statistics where stale_stats='YES' and
owner='APPS' and (table_name like 'CMP%' or table_name like'XXCMP%') and table_name
not in
('CMP_AS400_ORACLE_IFACE_TEMP','CMP_PO_EXT_TO_ISOLA_CTEMP','CMP_LABEL_INV_LOT_TEMP'
,'CMP_MFG_QUALITY_DATA','XXCMP_SF_OPPORTUNITIES_F','XXCMP_SF_MARKETSHARE_F','XXCMP_
SF_LOOKUP_VALUES') order by table_name;
EOF

cat /tmp/a.log >> /tmp/main.log


}

function gather_stats
{
cat /tmp/a.log | while read p
do
tbl=`echo $p | awk '{ print $1 }'`
owner=`echo $p | awk '{ print $2 }'`
SQL=`echo "Exec
dbms_stats.gather_table_stats('$owner','$tbl',ESTIMATE_PERCENT=>dbms_stats.auto_sam
ple_size,CASCADE=>True,degree=> 4);"`
echo $SQL >> /tmp/main.log
sqlplus -s / as sysdba <<EOF >> /tmp/main.log
alter session set container=CMPPROD;
Exec
dbms_stats.gather_table_stats('$owner','$tbl',ESTIMATE_PERCENT=>dbms_stats.auto_sam
ple_size,CASCADE=>True,degree=> 4);
EOF
done
}

PreChks
get_objects
gather_stats
get_objects
mail_subject="mvmrp1 Stale Stats Report"
cat "$LOGFILE" | mailx -s "${mail_subject}" ${MAIL_RECIPIENT_INFO}

You might also like