一、场景介绍
公司最近Oracle数据库出现归档日志超过归档空间阈值,导致数据库夯住无法正常使用;之前也出现过类似的
二、工具介绍
这里我们使用的是RMAN,RMAN(R
三、实践过程
1、自动清理脚本
- 脚本中我是清理了7天前的所有归档日志
[root@ localhost ~]# su - oracle
[oracle@localhost ~]$ mkdir /home/oracle/logs
[oracle@localhost ~]$ mkdir /home/oracle/script/
[oracle@localhost ~]$ cd script/
[oracle@localhost script]$ vim del_archivelog.sh
#!/bin/bash
oracle_env() {
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
}
arch_log_dir() {
if [ -d /home/oracle/logs ];then
echo "true"
else
mkdir -p /home/oracle/logs
fi
}
oracle_clean() {
oracle_env
exec >> /home/oracle/logs/delarch`date +%Y-%T`.log
$ORACLE_HOME/bin/rman target /<<EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 7';
exit;
EOF
}
main() {
arch_log_dir
oracle_clean
}
main
2、添加定时任务
- 注:我这里定时任务设置为,每周三凌晨整进行一次清理任务,大家可以根据自己项目中数据库实际的情况进行修改
[oracle@localhost ~]$ crontab -e
00 00 * * 3 . ~/.bash_profile; /home/oracle/script/del_archivelog.sh
必须 注册 为本站用户, 登录 后才可以发表评论!