archivelogs文件清理及使用失效归档的删除

Oracle在开启了归档模式后,会在指定的archive目录下产生很多的archivelog文件,而且默认是不会定期清除的,时间长久了,该文件夹会占用很大的空间。

问题:如何定期正确删除archivelog文件呢? 很多人直接在archive目录下删除文件,这样其实不能达到在Oracle CLF文件中删除文件记录的效果。

正确方法:

1.用RMAN连接目标DB:在命令行界面输入以下命令

RMAN targetsys/*@orcl**

2.在RMAN命令窗口中,输入如下命令:

crosscheckarchivelog all;

delete expired archivelog all;

   或者删除指定时间之前的archivelog:

DELETE ARCHIVELOG ALL COMPLETED BEFORE ‘SYSDATE-7'; (指定删除7天前的归档日志)

3.其它相关命令: 查看归档日志列表:

list archivelog all;

4.查看失效的归档日志列表:list expiredarchivelog all;

①.Crosscheck日志


$ rman target /
Recovery Manager: Release 9.2.0.4.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
connected to target database: AVATAR2 (DBID=2480694409)


RMAN> crosscheck archivelog all;

注意:以上crosscheck的2种提示英文对照为:

对归档日志的验证成功-----》validation failed for archived log 
对归档日志的验证失败-----> validation succeeded for archived lo



using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=25 devtype=DISK
validation failed for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2714.dbf recid=2702 stamp=545107659
validation failed for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2715.dbf recid=2703 stamp=545108268
...........
validation failed for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2985.dbf recid=2973 stamp=545399327
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2986.dbf recid=2974 stamp=545400820
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2987.dbf recid=2975 stamp=545401757
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2988.dbf recid=2976 stamp=545402716
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2989.dbf recid=2977 stamp=545403661
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2990.dbf recid=2978 stamp=545416946
validation succeeded for archived log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2991.dbf recid=2979 stamp=545406220
Crosschecked 278 objects


RMAN> 


②.使用delete expired archivelog all 命令删除所有过期归档日志:


RMAN> delete expired archivelog all;


released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=12 devtype=DISK


List of Archived Log Copies
Key    Thrd Seq    S Low Time  Name
------- ---- ------- - --------- ----
376    1    2714    X 23-NOV-16 =/opt/oracle/oradata/avatar2/archive/1_2714.dbf 
.....




③.简要介绍一下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-16        
  Backup Piece      125    01-NOV-16          /data1/oracle/orabak/full_1_541165816
Backup Set          131    16-NOV-16        
  Backup Piece      131    16-NOV-16          /data1/oracle/orabak/full_AVATAR2_20161116_131
....
Backup Set          173    06-DEC-16        
  Backup Piece      173    06-DEC-16          /data1/oracle/orabak/full_AVATAR2_20161206_173
Backup Set          179    11-DEC-16        
  Backup Piece      179    11-DEC-16          /data1/oracle/orabak/arch544588206.arc
.....
  Backup Piece      189    17-DEC-16          /data1/oracle/orabak/arch545106606.arc
Backup Set          190    17-DEC-16        
  Backup Piece      190    17-DEC-16          /data1/oracle/orabak/arch545106665.arc
Backup Set          191    20-DEC-16        
  Backup Piece      191    20-DEC-16          /data1/oracle/orabak/arch_AVATAR2_20161220_194
Archive Log          2973  20-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2985.dbf
Archive Log          2971  20-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2984.dbf
.....
Archive Log          2705  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2717.dbf
Archive Log          2716  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log          2703  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log          2702  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2714.dbf


④.使用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-16        
  Backup Piece      125    01-NOV-16          /data1/oracle/orabak/full_1_541165816
....
Archive Log          2716  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log          2703  17-DEC-16          /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log          2702  17-DEC-16          /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_20161206_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

恭喜,到这一步说明你的失效归档日志已经删除完成。定期清理备份的RMAN归档日志和过期备份




你可能感兴趣的:(Oracle)