前言
當(dāng)Oracle 歸檔日志滿了后,將無(wú)法正常登入oracle,需要?jiǎng)h除一部分歸檔日志才能正常登入ORACLE。
最近同事在工作中遇到一個(gè)問(wèn)題,他那邊的一套Oracle 11g數(shù)據(jù)庫(kù)使用RMAN沒(méi)辦法刪除舊的歸檔,導(dǎo)致磁盤(pán)使用率很高。
oracle@ps251n2s:[/opt/oracle/archive/db] ls -ltr |more
total 3059881082
-rw-r----- 1 oracle oinstall 725320704 May 20 2016 1_1_91233774.dbf
-rw-rw---- 1 oracle oinstall 1756937216 Jun 7 2016 1_2_91233774.dbf
-rw-rw---- 1 oracle oinstall 1756731392 Jun 21 2016 1_3_91233774.dbf
-rw-rw---- 1 oracle oinstall 1758001152 Jul 3 2016 1_4_91233774.dbf
-rw-rw---- 1 oracle oinstall 1756729344 Jul 15 2016 1_5_91233774.dbf
-rw-rw---- 1 oracle oinstall 1765750784 Jul 26 22:00 1_6_91233774.dbf
-rw-rw---- 1 oracle oinstall 1760346112 Aug 6 14:04 1_7_91233774.dbf
......
使用RMAN list archivelog all;
查看日志也沒(méi)有顯示舊歸檔日志的記錄
RMAN> list archivelog all;
using target database control file instead of recovery catalog
List of Archived Log Copies for database with db_unique_name DBS
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1206 1 1206 A 14-JAN-17
Name: /opt/oracle/archive/db/1_1206_91233774.dbf
1207 1 1207 A 14-JAN-17
Name: /opt/oracle/archive/db/1_1207_91233774.dbf
1208 1 1208 A 14-JAN-17
Name: /opt/oracle/archive/db/1_1208_91233774.dbf
......
使用crosscheck檢查也沒(méi)有查到舊歸檔日志記錄
RMAN> crosscheck archivelog all;
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=16 device type=DISK
validation succeeded for archived log
archived log file name=/opt/oracle/archive/db/1_1206_91233774.dbf RECID=1206 STAMP=933244655
validation succeeded for archived log
archived log file name=/opt/oracle/archive/db/1_1207_91233774.dbf RECID=1207 STAMP=933249510
validation succeeded for archived log
archived log file name=/opt/oracle/archive/db/1_1208_91233774.dbf RECID=1208 STAMP=933254500
validation succeeded for archived log
archived log file name=/opt/oracle/archive/db/1_1209_91233774.dbf RECID=1209 STAMP=933259445
validation succeeded for archived log
查看v$archived_log視圖也沒(méi)有舊歸檔日志記錄
解決過(guò)程
于是在網(wǎng)上找到一篇文章,大體意思是MAN刪除歸檔日志的依據(jù)是controlfile中記錄的歸檔日志,而不是你磁盤(pán)上實(shí)際存在的歸檔日志,如果你的歸檔日志已經(jīng)不在controlfile中就無(wú)法被RMAN識(shí)別到,也就無(wú)法被刪除。而致于歸檔信息何時(shí)在控制文件中被覆蓋,這由一個(gè)參數(shù)control_file_record_keep_time來(lái)控制。
查看數(shù)據(jù)庫(kù)中的參數(shù)是默認(rèn)的7天
SYS@db> show parameter CONTROL_FILE_RECORD_KEEP_TIME
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
control_file_record_keep_time integer 7
難道是在控制文件中歸檔日志的記錄條數(shù)只能保留7天的么?于是到MOS去找相關(guān)文檔找到一篇Why Are Controlfile Entries For Archived Logs Not Overwritten After CONTROL_FILE_RECORD_KEEP_TIME? (文檔 ID 1056085.1),文檔介紹CONTROL_FILE_RECORD_KEEP_TIME參數(shù)并不是強(qiáng)制在控制文件中保留多少天的歸檔日志條目,而是由V$CONTROLFILE_RECORD_SECTION視圖中的ARCHIVED LOG條目去控制的,當(dāng)RECORDS_TOTAL=RECORDS_USED時(shí)舊的歸檔日志就會(huì)被覆蓋掉。
于是查數(shù)據(jù)庫(kù)中的V$CONTROLFILE_RECORD_SECTION視圖,看到ARCHIVED LOG行的records_total=224意味著控制文件中只能保留224條歸檔日志文件信息。
SYS@dbs> select * from v$controlfile_record_section where type='ARCHIVED LOG';
TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED FIRST_INDEX LAST_INDEX LAST_RECID
---------------------------- ----------- ------------- ------------ ----------- ---------- ----------
ARCHIVED LOG 584 224 224 88 87 1235
查詢v$archived_log視圖,總數(shù)為224條
SYS@dbs> select count(*) from v$archived_log;
COUNT(*)
----------
224
這時(shí)應(yīng)該可以推斷出由于控制文件中只能保留224條歸檔日志數(shù)據(jù),所以以前的歸檔信息已經(jīng)被控制文件刷出,RMAN無(wú)法識(shí)別到這些歸檔文件,所以就無(wú)法刪除這些歸檔日志。
那么現(xiàn)在如果使用RMAN刪除這些舊的歸檔日志呢?我想到使用catalog start with
命令重新注冊(cè)這些文件到控制文件中
RMAN> catalog start with '/opt/oracle/archive/db';
......
File Name: /opt/oracle/archive/db/1_1005_91233774.dbf
File Name: /opt/oracle/archive/db/1_1006_91233774.dbf
File Name: /opt/oracle/archive/db/1_1007_91233774.dbf
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
......
RMAN> list archivelog all;
.....
1236 1 301 A 22-OCT-16
Name: /opt/oracle/archive/db/1_301_91233774.dbf
1237 1 302 A 22-OCT-16
Name: /opt/oracle/archive/db/1_302_91233774.dbf
......
舊的歸檔日志文件已經(jīng)注冊(cè)到控制文件中了,再使用RMAN進(jìn)行刪除就可以了
delete archivelog until logseq 1007;
再次查詢v$controlfile_record_section視圖,records_total也被“撐”大了
SYS@db> select * from v$controlfile_record_section where type='ARCHIVED LOG';
TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED FIRST_INDEX LAST_INDEX LAST_RECID
---------------------------- ----------- ------------- ------------ ----------- ---------- ----------
ARCHIVED LOG 584 896 742 807 652 1800
至此問(wèn)題結(jié)束。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
您可能感興趣的文章:- Oracle RMAN快速入門(mén)指南
- rman恢復(fù)方案和oracle異機(jī)恢復(fù)
- ORACLE 數(shù)據(jù)庫(kù)RMAN備份恢復(fù)
- win平臺(tái)oracle rman備份和刪除dg備庫(kù)歸檔日志腳本
- Oracle RMAN自動(dòng)備份控制文件方法介紹
- Oracle RMAN還原時(shí)set newname文件名有空格報(bào)錯(cuò)的解決方法