oracle 定期copy 大表统计信息(分区表)

[oracle@test ~]$ cat /home/oracle/copy_statics.sh
#!/bin/bash
source /home/oracle/.bash_profile
SDATE=$(date  +%Y%m)
TDATE=$(date -d 'next-month' +%Y%m)
SPNAME="P"${SDATE}
TPNAME="P"${TDATE}
#echo $SPNAME
#echo $TPNAME
exec >> /home/oracle/copy_statics`date +%y%m%d%H`.log
sqlplus / as sysdba << EOF
set timing on
EXEC DBMS_STATS.UNLOCK_TABLE_STATS ('TEST','T_TEST_TR_TEST');
EXEC DBMS_STATS.UNLOCK_TABLE_STATS ('TEST','T_TEST_TR_TEST_EX_TEST');
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_CUP_Z_TR_TEST', '$SPNAME', '$TPNAME',FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_TR_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_TR_TEST_EX_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
EXEC DBMS_STATS.LOCK_TABLE_STATS ('TEST','T_TEST_TR_TEST');
EXEC DBMS_STATS.LOCK_TABLE_STATS ('TEST','T_TEST_TR_TEST_EX_TEST'); 
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_PSMTCK_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_HE_TR_TEST', '$SPNAME', '$TPNAME',FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_SIG_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_ESIG_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('TEST', 'T_TEST_CUP_TRA_TEST', '$SPNAME', '$TPNAME', FORCE=>TRUE);
exit;
EOF

 

posted @ 2018-04-25 11:28  钱若梨花落  阅读(675)  评论(0编辑  收藏  举报