如何正确删除Oracle 归档日志文件?
当Oracle中的归档日志空间满时,则需要把它清空,否则将会影响数据库正常运行,
将无法正常登入ORACLE,需要删除一部分归档日志才能正常登入ORACLE。
一、首先删除归档日志物理文件,归档日志一般都是位于archive目录下,在Oracle 10g中AIX系统下文件格式为“1_17884_XXX.dbf”,建议操作前先对数据库进行备份,删除时至少保留最近几天的日志用于数据库恢复。
二、把归档日志的物理文件删除后,我们就可以正常登入ORACLE了,但是还没完全把归档日志删除干净,ORACLE的controlfile中仍然记录着这些archivelog的信息,在oracle的OEM管理器中有可视化的日志展现出,当我们手工清除archive目录下的文件后,这些记录并没有被我们从controlfile中清除掉,接下去我们要做的就是这个工作。
1.指定数据库实例
登录数据库
2.连接数据库
>RMAN TARGET / --由于没有使用catalog 只能nocatalog方式登录
3.查看归档日志的状态
RMAN> list archivelog all;--显示全部的归档日志信息
4.手工删除归档日志文件
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
说明:
SYSDATA-7,表明当前的系统时间7天前,before关键字表示在7天前的归档日志,如果使用了闪回功能,也会删除闪回的数据。
同样道理,也可以删除从7天前到现在的全部日志,不过这个命令要考虑清楚,做完这个删除,最好马上进行全备份数据库
DELETE ARCHIVELOG from TIME 'SYSDATE-7'; 删除从7天前到现在的全部日志,慎用
UNIX/LINUX下也可以通过FIND找到7天前的归档数据,使用EXEC子操作删除
find /oraarchive -xdev -mtime +7 -name "*.dbf" -exec rm -f {} ;
这样做仍然会在RMAN里留下未管理的归档文件
仍需要在RMAN里执行下面2条命令
rman target /
crosscheck archivelog all;
delete expired archivelog all;
YES
----------------------------------
手动删除实际操作步骤:
用oracle用户登陆rman并连接数据库
rman target /
校验日志的可用性
crosscheck archivelog all;
显示全部的归档日志信息
list archivelog all;
列出所有失效的归档日志
list expired archivelog all;
删除列出所有失效的归档日志
delete expired archivelog all;
YES
如果日志爆了,用以上命令可能不起作用,可以使用下面的命令强行删除所有日志
delete noprompt force expired archivelog all;
list expired archivelog all;
list archivelog all;
----------------------------------
5、再次进行手工全库备份
backup database
同时备份控制文件、参数文件、归档日志
6、在使用report obsolete命令报告过期备份
7、再使用delete obsolete命令删除过期备份,若不能删除,可以再加一个参数 force强制删除
简要介绍一下report obsolete命令
使用report obsolete命令报告过期备份
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 125 01-NOV-04
Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804
Backup Set 131 04-NOV-04
Backup Piece 131 04-NOV-04 /data1/oracle/orabak/full_AVATAR2_20041104_131
....
Backup Set 173 06-DEC-04
Backup Piece 173 06-DEC-04 /data1/oracle/orabak/full_AVATAR2_20041206_173
Backup Set 179 11-DEC-04
Backup Piece 179 11-DEC-04 /data1/oracle/orabak/arch544588206.arc
.....
Backup Piece 189 17-DEC-04 /data1/oracle/orabak/arch545106606.arc
Backup Set 190 17-DEC-04
Backup Piece 190 17-DEC-04 /data1/oracle/orabak/arch545106665.arc
Backup Set 191 20-DEC-04
Backup Piece 191 20-DEC-04 /data1/oracle/orabak/arch_AVATAR2_20041220_194
Archive Log 2973 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2985.dbf
Archive Log 2971 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2984.dbf
.....
Archive Log 2705 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2717.dbf
Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf
4.使用delete obsolete命令删除过期备份:
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 125 01-NOV-04
Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804
....
Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/data1/oracle/orabak/full_AVATAR2_20041206_173 recid=173 stamp=544156241
.....
deleted archive log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2715.dbf recid=2703 stamp=545108268
deleted archive log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2714.dbf recid=2702 stamp=545107659
Deleted 286 objects
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=19 devtype=DISK
specification does not match any archive log in the recovery catalog
5 在rman中用crosscheck检查归档日志,2个归档日志都是失败的:
RMAN> crosscheck archivelog all;
释放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 记录 ID=1 时间戳 =572866
683
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 记录 ID=2 时间戳 =57286
6931
已交叉检验的 2 对象
6 试着同步一下,看行不行,结果不行,crosscheck还是失败:
RMAN> resync catalog;
正在启动全部恢复目录的 resync
完成全部 resync
RMAN> crosscheck archivelog all;
释放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 记录 ID=1 时间戳 =572866
683
对归档日志的验证失败
存档日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 记录 ID=2 时间戳 =57286
6931
已交叉检验的 2 对象
7 用list expired看看是否有失效的archive log,证明没有失效的archive log:
RMAN> list expired archivelog all;
说明与恢复目录中的任何存档日志均不匹配
8 更改语言环境试试,结果再次crosscheck,2个archive log 都成功了:
RMAN> exit
恢复管理器完成。
C:>set nls_lang=american_america.zhs16gbk
C:>rman catalogrman/rman@safetarget /
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: TEST (DBID=1870953724)
connected to recovery catalog database
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE1_47.DBF recid=1 stamp=57286
6683
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE11_48.DBF recid=2 stamp=5728
66931
Crosschecked 2 objects
2、使用rman清理归档日志
RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息。
可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式。
对于上述的三种方式又可以配合from, until, between .. and .. 等等子句来限定范围,方式灵活多变。
下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的:
delete noprompt archivelog until time "to_date('XXXX-XX-XX','YYYY-MM-DD')"; ---> 清理到某天日期之前的归档
delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD hh24:mi:ss')"; ---> 清理到具体时分秒之前的归档日志
cross check archivelog all; --->校验日志的可用性
list expired archivelog all; --->列出所有失效的归档日志
delete archivelog until sequence 16; --->删除log sequence为16及16之前的所有归档日志
delete archivelog all completed before 'sysdate-7'; --->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
delete archivelog from time 'sysdate-1'; --->注意这个命令,删除系统时间1天以内到现在的归档日志
delete noprompt archivelog all completed before 'sysdate'; --->该命令清除当前所有的归档日志
delete noprompt archivelog all completed before 'sysdate-0'; --->该命令清除当前所有的归档日志
delete noprompt archivelog all; --->同上一命令
自动化脚本实现清理
#对于RAC环境或者ASM需要清除archive,使用shell脚本调用RMAN是比较妥当的方式
#其次,如果你的archive位于闪回区,制定合理的保留策略,也可以让Oracle自动老化无用的归档日志
robin@SZDB:~/dba_scripts/custom/bin> cat clean_arch.sh
#!/bin/bash
#cd /u01/app/ora/data/zst/archive/
#find . -mtime +14 |xargs rm -rf
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
#if [ -z "${1}" ];then
# echo "Usage: "
# echo " `basename $0` ORACLE_SID"
# exit 1
#fi
#ORACLE_SID=$1; export ORACLE_SID
rman log=~/rman.log <<EOF
connect target /
run{
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 14';
}
exit;
EOF
echo "done"
4、小结
a、归档日志清除的方法最好是在RMAN方式下完成,这样子是最彻底的清除方式
b、对于生产环境应考虑在RMAN备份的时候清除归档日志,如backup archivelog all时使用delete input与delete all input清除归档日志
c、如果备份期间不清除归档日志则arch会很大,造成归档磁盘满而导致归档失败。建议还是删除或考虑存放到闪回区
d、如果清除大部分又想保留最近的,则使用delete noprompt archivelog all completed before 'sysdate - n'方式
e、详细的清除归档日志语法: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#RCMRF106
————————————————
[root@hch_test_121_90 ~]# more archivelog_clear.sh
#!/bin/sh
BACK_DIR=/oracle/clear_archlog/data
export DATE=`date +%F`
echo " " >> $BACK_DIR/$DATE/rman_backup.log
echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
su - oracle -c "
mkdir -p $BACK_DIR/$DATE
rman log=$BACK_DIR/$DATE/rman_backup.log target / <<EOF
# delete force archivelog all completed before 'sysdate-1/24'; # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数
delete force noprompt archivelog all completed before 'sysdate-1/24';
exit;
EOF
"
echo " " >> $BACK_DIR/$DATE/rman_backup.log
crontab定时任务
[root@hch_test_121_90 ~]# crontab -l
10 */1 * * * sh /home/oracle/archivelog_clear.sh
------------------------------------------
Oracle RMAN 清除归档日志
原创Leshami 最后发布于2013-07-12 11:03:36 阅读数 44565 收藏
展开
在开发环境及UAT环境经常碰到需要清除归档日志的情形,对于这个问题方法有很多。可以直接使用rm方式清除归档日志,也可以使用find命令来查找符合条件的记录来清除归档日志,或者直接写个shell脚本来搞定。这样在DEV或者UAT还可以,但是在Prod环境还是建议使用RMAN提供的命令来搞定比较妥当。因为rm,find方式删除了实际的归档日志也释放了空间,但对应的存储在控制文件中的归档信息并没有彻底清除。依旧占用着一些空间未能及时清除而需要控制文件通过age out方式来释放空间。本文描述了使用RMAN方式来清除归档日志,同时也可以将其部署到shell脚本中使用。
有关阅读本文需要的相关参考
Oracle 归档日志
Oracle 控制文件(CONTROLFILE)
Oracle 联机重做日志文件(ONLINE LOG FILE)
delete archivelog all 无法彻底删除归档日志?
Linux/Unix shell 脚本中调用SQL,RMAN脚本
Linux/Unix shell 脚本清除归档日志文件
1、清除归档日志的方式
a、手动删除
使用rm 或者find方式来删除,通过该方式删除之后,在RMAN下可以通过 crosscheck archivelog all 校验归档是否失效,如下面的操作:
rm -rf arch_816906485_1_10.arc
find /u02/database/GOBO1/archive/ -ctime +0 -delete
RMAN> crosscheck archivelog all
b、使用RMAN方式清除
RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息。
可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式。
对于上述的三种方式又可以配合from, until, between .. and .. 等等子句来限定范围,方式灵活多变。
下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的:
crosscheck archivelog all; --->校验日志的可用性
list expired archivelog all; --->列出所有失效的归档日志
delete archivelog until sequence 16; --->删除log sequence为16及16之前的所有归档日志
delete archivelog all completed before 'sysdate-7'; --->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
delete archivelog from time 'sysdate-1'; --->注意这个命令,删除系统时间1天以内到现在的归档日志
delete noprompt archivelog all completed before 'sysdate'; --->该命令清除所有的归档日志
delete noprompt archivelog all; --->同上一命令
2、演练使用RMAN清除归档日志
robin@SZDB:~> export ORACLE_SID=GOBO1
robin@SZDB:~> rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Thu Jul 11 17:07:00 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GOBO1 (DBID=733951103)
RMAN> host;
robin@SZDB:~> cd /u02/database/GOBO1/archive/
robin@SZDB:/u02/database/GOBO1/archive> ls
arch_816906485_1_10.arc arch_816906485_1_12.arc
arch_816906485_1_11.arc arch_816906485_1_13.arc
............
robin@SZDB:/u02/database/GOBO1/archive> rm -rf arch_816906485_1_10.arc arch_816906485_1_11.arc arch_816906485_1_12.arc
robin@SZDB:/u02/database/GOBO1/archive> exit;
exit
host command complete
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_9.arc recid=2085 stamp=817211151
validation failed for archived log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_10.arc recid=2086 stamp=817250793
..............
validation succeeded for archived log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049
Crosschecked 83 objects
RMAN> list expired archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2086 1 10 X 20130604 11:05:51 /u02/database/GOBO1/archive/arch_816906485_1_10.arc
2087 1 11 X 20130604 22:06:17 /u02/database/GOBO1/archive/arch_816906485_1_11.arc
2088 1 12 X 20130605 19:30:53 /u02/database/GOBO1/archive/arch_816906485_1_12.arc
RMAN> delete archivelog until sequence 16;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2084 1 8 A 20130604 09:53:17 /u02/database/GOBO1/archive/arch_816906485_1_8.arc
.................
2092 1 16 A 20130607 22:03:23 /u02/database/GOBO1/archive/arch_816906485_1_16.arc
Do you really want to delete the above objects (enter YES or NO)? yes
...............
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_16.arc recid=2092 stamp=817516861
Deleted 9 objects
RMAN> delete archivelog all completed before 'sysdate-7';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2093 1 17 A 20130608 00:01:00 /u02/database/GOBO1/archive/arch_816906485_1_17.arc
2094 1 18 A 20130608 18:00:17 /u02/database/GOBO1/archive/arch_816906485_1_18.arc
...........
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_72.arc recid=2148 stamp=819847035
Deleted 56 objects
RMAN> list copy of database archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2149 1 73 A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc
2150 1 74 A 20130704 22:00:19 /u02/database/GOBO1/archive/arch_816906485_1_74.arc
2151 1 75 A 20130704 22:04:40 /u02/database/GOBO1/archive/arch_816906485_1_75.arc
...............
2164 1 88 A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arc
2165 1 89 A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc
2166 1 90 A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arc
RMAN> delete archivelog from time 'sysdate-1';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2165 1 89 A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc
2166 1 90 A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arc
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_89.arc recid=2165 stamp=820447373
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049
Deleted 2 objects
RMAN> delete archivelog all completed before 'sysdate - 1';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2149 1 73 A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc
.......................
2164 1 88 A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arc
Do you really want to delete the above objects (enter YES or NO)? yes
................
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_88.arc recid=2164 stamp=820414835
Deleted 16 objects
RMAN> sql " alter system archive log current";
sql statement: alter system archive log current
RMAN> list copy of archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2167 1 91 A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arc
RMAN> delete noprompt archivelog all completed before 'sysdate';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2167 1 91 A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arc
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_91.arc recid=2167 stamp=820517964
Deleted 1 objects
3、清除归档日志简单的shell脚本
#对于RAC环境或者ASM需要清除archive,使用shell脚本调用RMAN是比较妥当的方式
#其次,如果你的archive位于闪回区,制定合理的保留策略,也可以让Oracle自动老化无用的归档日志
robin@SZDB:~/dba_scripts/custom/bin> more clean_arch.sh
# +-------------------------------------------------------+
# + Clean archived log as specified time |
# + Author : Robinson |
# + Blog : http://blog.csdn.net/robinson_0612 |
# + Usage : |
# + clean_arch.sh $ORACLE_SID |
# +-------------------------------------------------------+
#
#!/bin/bash
# --------------------
# Define variable
# --------------------
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
if [ -z "${1}" ];then
echo "Usage: "
echo " `basename $0` ORACLE_SID"
exit 1
fi
ORACLE_SID=$1; export ORACLE_SID
$ORACLE_HOME/bin/rman log=/users/robin/log/rman.log <<EOF
connect target /
run{
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 1';
}
exit;
EOF
exit
4、小结
a、归档日志清除的方法最好是在RMAN方式下完成,这样子是最彻底的清除方式
b、对于生产环境应考虑在RMAN备份的时候清除归档日志,如backup archivelog all时使用delete input与delete all input清除归档日志
c、如果备份期间不清除归档日志则arch会很大,造成归档磁盘满而导致归档失败。建议还是删除或考虑存放到闪回区
d、如果清除大部分又想保留最近的,则使用delete noprompt archivelog all completed before 'sysdate - n'方式
e、详细的清除归档日志语法: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#RCMRF106
相关参考
Oracle 冷备份
Oracle 热备份
Oracle 备份恢复概念
Oracle 实例恢复
Oracle 基于用户管理恢复的处理
SYSTEM 表空间管理及备份恢复
SYSAUX表空间管理及恢复
Oracle 基于备份控制文件的恢复(unsing backup controlfile)
RMAN 概述及其体系结构
RMAN 配置、监控与管理
RMAN 备份详解
RMAN 还原与恢复
RMAN catalog 的创建和使用
基于catalog 创建RMAN存储脚本
基于catalog 的RMAN 备份与恢复
RMAN 备份路径困惑
自定义 RMAN 显示的日期时间格式
只读表空间的备份与恢复
Oracle 基于用户管理的不完全恢复
理解 using backup controlfile
使用RMAN实现异机备份恢复(WIN平台)
使用RMAN迁移文件系统数据库到ASM
基于Linux下 Oracle 备份策略(RMAN)
Linux 下RMAN备份shell脚本
使用RMAN迁移数据库到异机
RMAN 提示符下执行SQL语句
Oracle 基于 RMAN 的不完全恢复(incomplete recovery by RMAN)
————————————————
版权声明:本文为CSDN博主「Leshami」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/robinson_0612/java/article/details/9308287
业务增长发展迅猛,归档日志增长太快,磁盘承受不了,所以准备做个定时清理归档日志的定时任务
ORACLE 定时清理归档日志详细过程
1、RM方式清理归档日志
清理归档日志,可以人为的删除已经归档好的日志文件,然后再调用rman里面RMAN> crosscheck archivelog all;来去数据库里面删除归档记录;也可以通过ram调用delete命令来删除归档日志。
2、使用rman清理归档日志
RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息。
可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式。
对于上述的三种方式又可以配合from, until, between .. and .. 等等子句来限定范围,方式灵活多变。
下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的:
delete noprompt archivelog until time "to_date('XXXX-XX-XX','YYYY-MM-DD')"; ---> 清理到某天日期之前的归档
delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD hh24:mi:ss')"; ---> 清理到具体时分秒之前的归档日志
cross check archivelog all; --->校验日志的可用性
list expired archivelog all; --->列出所有失效的归档日志
delete archivelog until sequence 16; --->删除log sequence为16及16之前的所有归档日志
delete archivelog all completed before 'sysdate-7'; --->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
delete archivelog from time 'sysdate-1'; --->注意这个命令,删除系统时间1天以内到现在的归档日志
delete noprompt archivelog all completed before 'sysdate'; --->该命令清除当前所有的归档日志
delete noprompt archivelog all completed before 'sysdate-0'; --->该命令清除当前所有的归档日志
delete noprompt archivelog all; --->同上一命令
3、实现清理一个小时前的归档日志
执行命令:delete force archivelog all completed before 'sysdate-1/24';
(1)查看当前时间
[oracle@hch_test_121_90 ~]$ date
Tue Oct 11 11:20:20 CST 2016
[oracle@hch_test_121_90 ~]$
(2)查看当前一个小时之前的归档日志,看到有一个o1_mf_1_2822_czrm1dj8_.arc,如下所示:
[oracle@hch_test_121_90 ~]$ ll /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/ |more
total 3181880
-rw-r----- 1 oracle oinstall 41340416 Oct 11 10:19 o1_mf_1_2822_czrm1dj8_.arc
-rw-r----- 1 oracle oinstall 40434176 Oct 11 10:20 o1_mf_1_2823_czrm49l9_.arc
-rw-r----- 1 oracle oinstall 41180160 Oct 11 10:22 o1_mf_1_2824_czrm76nd_.arc
-rw-r----- 1 oracle oinstall 40340480 Oct 11 10:23 o1_mf_1_2825_czrm9xos_.arc
(3)开始执行删除命令,按计划删除这一条归档日志
RMAN> delete force archivelog all completed before 'sysdate-1/24';
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 device type=DISK
List of Archived Log Copies for database with db_unique_name POWERDES
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1396 1 2822 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc
Do you really want to delete the above objects (enter YES or NO)? YES # 输入删除命令
deleted archived log
archived log file name=/oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc RECID=1396 STAMP=924949164
Deleted 1 objects
RMAN>
4、自动化脚本定时任务实现清理一个小时前的归档日志
(1)自动化脚本
[root@hch_test_121_90 ~]# more archivelog_clear.sh
#!/bin/sh
BACK_DIR=/oracle/clear_archlog/data
export DATE=`date +%F`
echo " " >> $BACK_DIR/$DATE/rman_backup.log
echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
su - oracle -c "
mkdir -p $BACK_DIR/$DATE
rman log=$BACK_DIR/$DATE/rman_backup.log target / <<EOF
# delete force archivelog all completed before 'sysdate-1/24'; # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数
delete force noprompt archivelog all completed before 'sysdate-1/24';
exit;
EOF
"
echo " " >> $BACK_DIR/$DATE/rman_backup.log
(2)crontab定时任务
[root@hch_test_121_90 ~]# crontab -l
10 */1 * * * sh /home/oracle/archivelog_clear.sh
(3)查看执行后的日志
[root@hch_test_121_90 ~]# more /oracle/clear_archlog/data/2016-10-11/rman_backup.log
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Oct 11 11:28:04 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: POWERDES (DBID=3458668465)
RMAN>
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 device type=DISK
List of Archived Log Copies for database with db_unique_name POWERDES
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1397 1 2823 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2823_czrm49l9_.arc
1398 1 2824 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2824_czrm76nd_.arc
1399 1 2825 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2825_czrm9xos_.arc
1400 1 2826 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2826_czrmdqqy_.arc
1401 1 2827 A 11-OCT-16
Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2827_czrmhksn_.arc
Do you really want to delete the above objects (enter YES or NO)? "exit;" is an invalid response - please re-enter.
Do you really want to delete the above objects (enter YES or NO)?
Error occurred getting response - assuming NO response
RMAN>
Recovery Manager complete.
作者:泡菜爱上WaSabi
链接:https://www.jianshu.com/p/a8031357c65d
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。