今天同事问到一个问题,他那边的一套11g数据库使用RMAN没办法删除旧的归档,导致磁盘使用率很高。要来ip登录上去一看确实是,最旧的归档日志是16年5月的。
oracle@ps251n2s:[/opt/oracle/archive/db]ls-ltr|more total3059881082 -rw-r-----1oracleoinstall725320704May2020161_1_91233774.dbf -rw-rw----1oracleoinstall1756937216Jun720161_2_91233774.dbf -rw-rw----1oracleoinstall1756731392Jun2120161_3_91233774.dbf -rw-rw----1oracleoinstall1758001152Jul320161_4_91233774.dbf -rw-rw----1oracleoinstall1756729344Jul1520161_5_91233774.dbf -rw-rw----1oracleoinstall1765750784Jul2622:001_6_91233774.dbf -rw-rw----1oracleoinstall1760346112Aug614:041_7_91233774.dbf ......
使用RMAN list archivelog all;查看日志也没有显示旧归档日志的记录
RMAN>listarchivelogall; usingtargetdatabasecontrolfileinsteadofrecoverycatalog ListofArchivedLogCopiesfordatabasewithdb_unique_nameDBS ===================================================================== KeyThrdSeqSLowTime ---------------------------- 120611206A14-JAN-17 Name:/opt/oracle/archive/db/1_1206_91233774.dbf 120711207A14-JAN-17 Name:/opt/oracle/archive/db/1_1207_91233774.dbf 120811208A14-JAN-17 Name:/opt/oracle/archive/db/1_1208_91233774.dbf ......
使用crosscheck检查也没有查到旧归档日志记录
RMAN>crosscheckarchivelogall; usingtargetdatabasecontrolfileinsteadofrecoverycatalog allocatedchannel:ORA_DISK_1 channelORA_DISK_1:SID=16devicetype=DISK validationsucceededforarchivedlog archivedlogfilename=/opt/oracle/archive/db/1_1206_91233774.dbfRECID=1206STAMP=933244655 validationsucceededforarchivedlog archivedlogfilename=/opt/oracle/archive/db/1_1207_91233774.dbfRECID=1207STAMP=933249510 validationsucceededforarchivedlog archivedlogfilename=/opt/oracle/archive/db/1_1208_91233774.dbfRECID=1208STAMP=933254500 validationsucceededforarchivedlog archivedlogfilename=/opt/oracle/archive/db/1_1209_91233774.dbfRECID=1209STAMP=933259445 validationsucceededforarchivedlog
查看v$archived_log视图也没有旧归档日志记录
于是百度找到一篇文章http://3y.uu456.com/bp_3i90z4529l10ttd0odyk_1.html大体意思是MAN删除归档日志的依据是controlfile中记录的归档日志,而不是你磁盘上实际存在的归档日志
,如果你的归档日志已经不在controlfile中就无法被RMAN识别到,也就无法被删除。而致于归档信息何时在控制文件中被覆盖,这由一个参数control_file_record_keep_time来控制。
查看数据库中的参数是默认的7天
SYS@db>showparameterCONTROL_FILE_RECORD_KEEP_TIME NAMETYPEVALUE -------------------------------------------------------------------------------------------------- control_file_record_keep_timeinteger7
难道是在控制文件中归档日志的记录条数只能保留7天的么?于是到MOS去找相关文档找到一篇Why Are Controlfile Entries For Archived Logs Not Overwritten After CONTROL_FILE_RECORD_KEEP_TIME? (文档 ID 1056085.1),文档介绍CONTROL_FILE_RECORD_KEEP_TIME参数并不是强制在控制文件中保留多少天的归档日志条目,而是由V$CONTROLFILE_RECORD_SECTION视图中的ARCHIVED LOG条目去控制的,当RECORDS_TOTAL=RECORDS_USED时旧的归档日志就会被覆盖掉。
于是查数据库中的V$CONTROLFILE_RECORD_SECTION视图,看到ARCHIVED LOG行的records_total=224意味着控制文件中只能保留224条归档日志文件信息。
SYS@dbs>select*fromv$controlfile_record_sectionwheretype='ARCHIVEDLOG'; TYPERECORD_SIZERECORDS_TOTALRECORDS_USEDFIRST_INDEXLAST_INDEXLAST_RECID ----------------------------------------------------------------------------------------------- ARCHIVEDLOG58422422488871235
查询v$archived_log视图,总数为224条
SYS@dbs>selectcount(*)fromv$archived_log; COUNT(*) ---------- 224
这时应该可以推断出由于控制文件中只能保留224条归档日志数据,所以以前的归档信息已经被控制文件刷出,RMAN无法识别到这些归档文件,所以就无法删除这些归档日志。
那么现在如果使用RMAN删除这些旧的归档日志呢?我想到使用catalog start with 命令重新注册这些文件到控制文件中
RMAN>catalogstartwith'/opt/oracle/archive/db'; ...... FileName:/opt/oracle/archive/db/1_1005_91233774.dbf FileName:/opt/oracle/archive/db/1_1006_91233774.dbf FileName:/opt/oracle/archive/db/1_1007_91233774.dbf Doyoureallywanttocatalogtheabovefiles(enterYESorNO)?yes catalogingfiles... catalogingdone ...... RMAN>listarchivelogall; ..... 12361301A22-OCT-16 Name:/opt/oracle/archive/db/1_301_91233774.dbf 12371302A22-OCT-16 Name:/opt/oracle/archive/db/1_302_91233774.dbf ......
旧的归档日志文件已经注册到控制文件中了,再使用RMAN进行删除就可以了
deletearchiveloguntillogseq1007;
再次查询v$controlfile_record_section视图,records_total也被“撑”大了
SYS@db>select*fromv$controlfile_record_sectionwheretype='ARCHIVEDLOG'; TYPERECORD_SIZERECORDS_TOTALRECORDS_USEDFIRST_INDEXLAST_INDEXLAST_RECID ----------------------------------------------------------------------------------------------- ARCHIVEDLOG5848967428076521800
至此问题结束。