oracle 锁定 当前分区
vi copy_status.sh
#!/bin/bash
source /home/oracle/.bash_profile
SDATE=$(date +%Y%m%d)
TDATE1=$(date -d '+1 day' +%Y%m%d)
TDATE2=$(date -d '+2 day' +%Y%m%d)
SPNAME="P"${SDATE}
TPNAME1="P"${TDATE1}
TPNAME2="P"${TDATE2}
#echo $SPNAME
#echo $TPNAME1
#echo $TPNAME2
exec >> /home/oracle/log/copy_statics`date +%Y%m%d%H`.log
sqlplus / as sysdba << EOF
set timing on
EXEC DBMS_STATS.UNLOCK_PARTITION_STATS ('DL','D_AI_OER','$TPNAME1');
EXEC DBMS_STATS.COPY_TABLE_STATS ('DL', 'D_AI_OER', '$SPNAME', '$TPNAME1', FORCE=>TRUE);
EXEC DBMS_STATS.COPY_TABLE_STATS ('DL', 'D_AI_OER', '$SPNAME', '$TPNAME2', FORCE=>TRUE);
EXEC DBMS_STATS.LOCK_PARTITION_STATS ('DEAL','D_AI_OER','$TPNAME2');
exit;
EOF
vi copy.sh
#!/bin/bash
source /home/oracle/.bash_profile
SDATE1=$(date -d "-0 day" +%Y%m%d)
TDATE1=$(date -d "+1 day" +%Y%m%d)
SPNAME1="P"${SDATE1}
TPNAME1="P"${TDATE1}
#echo $SPNAME1
#echo $TPNAME1
exec >> /home/oracle/copy_log/copy_statics_dat`date +%y%m%d%H`.log
sqlplus / as sysdba << EOF
set timing on
EXEC DBMS_STATS.UNLOCK_PARTITION_STATS ('DL','D_AI_OER','$TPNAME1');
EXEC DBMS_STATS.COPY_TABLE_STATS ('DL', 'D_AI_OER', '$SPNAME1', '$TPNAME1', FORCE=>TRUE);
EXEC DBMS_STATS.LOCK_PARTITION_STATS ('DL','D_AI_OER','$TPNAME1');
EXEC DBMS_STATS.UNLOCK_PARTITION_STATS ('DL','D_AI_LER','$TPNAME1');
EXEC DBMS_STATS.COPY_TABLE_STATS ('DL', 'D_AI_LER', '$SPNAME1', '$TPNAME1', FORCE=>TRUE);
EXEC DBMS_STATS.LOCK_PARTITION_STATS ('DL','D_AI_LER','$TPNAME1');
EXEC DBMS_STATS.UNLOCK_PARTITION_STATS ('DL','D_AI_OER_EXT','$TPNAME1');
EXEC DBMS_STATS.COPY_TABLE_STATS ('DL', 'D_AI_OER_EXT', '$SPNAME1', '$TPNAME1', FORCE=>TRUE);
EXEC DBMS_STATS.LOCK_PARTITION_STATS ('DL','D_AI_OER_EXT','$TPNAME1');
exit;
EOF