Oracle 開啟歸檔模式后,會一直不停的產(chǎn)生歸檔日志,如果不定時刪除,遲早會撐爆磁盤空間,所以就需要布置定時刪除歸檔日志的腳本!
至于為什么要開啟歸檔模式,還有怎么開啟歸檔模式!請參考:Oracle 開啟歸檔模式
Linux 下刪除歸檔腳本:
mkdir -p /home/oracle/scripts/log
vi /home/oracle/scripts/del_arch.sh
#!/bin/bash
source ~/.bash_profile
DAY_TAG=`date +"%Y-%m-%d"`
rman target / nocatalog msglog /home/oracle/scripts/log/del_arch_$DAY_TAG.log<<EOF
crosscheck archivelog all;
delete noprompt archivelog until time '(sysdate-7)';
delete noprompt force archivelog until time 'SYSDATE-10';
EOF
## 寫入crontab
crontab -e
# 00 07 * * * /home/oracle/scripts/del_arch.sh
Windows 下刪除歸檔腳本:
編輯 del_arch.bat
腳本:
@echo off
set ORACLE_SID=orcl
set "filename=del_arch_task_log_%date:~0,4%%date:~5,2%%date:~8,2%.log"
(
echo.
echo ====================cleaning %date% %time% =========================
echo.
rman target / cmdfile=G:\scripts\del_arch.sql
echo.
echo ===================== finish %date% %time% =========================
echo.
)>>G:\scripts\%filename% 2>&1<nul
編輯 del_arch.sql
腳本:
run{
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-1/2';
delete noprompt force archivelog until time 'SYSDATE-1';
}
📢 注意:腳本中的目錄位置,請根據(jù)實際情況進行修改!
本次分享到此結(jié)束啦~
如果覺得文章對你有幫助,點贊、收藏、關(guān)注、評論,一鍵四連支持,你的支持就是我創(chuàng)作最大的動力。