1. 程式人生 > >Oracle RMAN 清除歸檔日誌

Oracle RMAN 清除歸檔日誌

      在開發環境及UAT環境經常碰到需要清除歸檔日誌的情形,對於這個問題方法有很多。可以直接使用rm方式清除歸檔日誌,也可以使用find命令來查詢符合條件的記錄來清除歸檔日誌,或者直接寫個shell指令碼來搞定。這樣在DEV或者UAT還可以,但是在Prod環境還是建議使用RMAN提供的命令來搞定比較妥當。因為rm,find方式刪除了實際的歸檔日誌也釋放了空間,但對應的儲存在控制檔案中的歸檔資訊並沒有徹底清除。依舊佔用著一些空間未能及時清除而需要控制檔案通過age out方式來釋放空間。本文描述了使用RMAN方式來清除歸檔日誌,同時也可以將其部署到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清除歸檔日誌  

[email protected]:~> export ORACLE_SID=GOBO1
[email protected]:~> 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;

[email protected]
:~> cd /u02/database/GOBO1/archive/ [email protected]:/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 ............ [email protected]:/u02/database/GOBO1/archive> rm -rf arch_816906485_1_10.arc arch_816906485_1_11.arc arch_816906485_1_12.arc [email protected]:/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自動老化無用的歸檔日誌
[email protected]:~/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&nbsp;牛鵬社

相關推薦

Oracle RMAN 清除歸檔日誌

      在開發環境及UAT環境經常碰到需要清除歸檔日誌的情形,對於這個問題方法有很多。可以直接使用rm方式清除歸檔日誌,也可以使用find命令來查詢符合條件的記錄來清除歸檔日誌,或者直接寫個shell指令碼來搞定。這樣在DEV或者UAT還可以,但是在Prod環境還是建議使

ORACLE Rman刪除歸檔日誌

刪除過期的歸檔日誌: RMAN> list archivelog all; 手工刪除歸檔日誌檔案 RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7'; 設定歸檔日誌過期時間: RMAN>show

檢視oracle歸檔日誌及空間佔用率,清除歸檔日誌

select * from v$flash_recovery_area_usage; --檢視空間佔用率  select * from v$recovery_file_dest;  --檢視歸檔日誌的存放地址; 使用rman清空歸檔日誌      crosscheck ar

ORACLE 使用RMAN管理歸檔日誌 archived log

oracle 歸檔日誌通常使用rman進行管理,作為備份集的一部分 正常情況下,可以根據方法刪除1 過期策略 crosscheck archivelog all;delete expired archivelog all;     ---這個只刪除過期的日誌 delete 

oracle 正確刪除歸檔日誌,並清除 V$ARCHIVED_LOG 資料

1. 連線 RMAN 管理 rman target /   2. 檢視歸檔日誌列表 RMAN> crosscheck archivelog all;   3. 刪除所有歸檔日誌 RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE '

通過RMAN刪除歸檔日誌不釋放問題

軟件 oracle 空間 google 操作系統 我的生產環境中歸檔日誌滿了,通過如下腳本刪除後,空間並沒有釋放,看有網友有相關的解決思路,可以跟大家一起分享一下:RMAN> crosscheck archivelog all;RMAN> delete expried arch

RMAN刪除歸檔日誌不釋放問題

oracle今天同事問到一個問題,他那邊的一套Oracle 11g數據庫使用RMAN沒辦法刪除舊的歸檔,導致磁盤使用率很高。[email protected]/* */:[/opt/oracle/archive/db] ls -ltr |moretotal 3059881082 -rw-r----

rman 還原歸檔日誌 restore archivelog

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

Linux系統Oracle定時刪除歸檔日誌

使用rman命令刪除做Oracle資料庫定期刪除歸檔日誌處理 1、準備工作: 以root使用者角色登入Linux作業系統,建立儲存刪除歸檔時記錄日誌及刪除shell指令碼檔案的目錄並授權給Oracle使用者,命令如下: mkdir -p /home/del_log    m

ORACLE 正確刪除歸檔日誌的方法

我們都知道在controlfile中記錄著每一個archivelog檔案的相關資訊,當然們在OS下把這些物理檔案delete掉後,在我們的controlfile中仍然記錄著這些archivelog檔案的相關資訊,在oracle的OEM管理器中有視覺化的日誌展現出,當我們手

rman進行歸檔日誌指定備份幾次以上的不備份

11.2.0.3資料庫環境,使用rman進行歸檔日誌備份,想實現: (1)每天備份歸檔日誌,備份完並不刪除歸檔日誌 (2)歸檔日誌備份成功一次之後,下次再備份的時候rman就自動不會再次備份這個歸檔日誌   這個需求可以通過 backup archivelog all not backed up; 語法來實現

使用RMAN刪除歸檔日誌和閃回日誌

ORACLE正確刪除歸檔並回收空間的方法 一 個ORACLE歸檔日誌經常滿,表現為/oraarchive 這個檔案空間佔用100%大家一定抱怨ORACLE為何沒有歸檔維護工具,很多人直接刪除了事,錯了,ORACLE有,而且很智慧,可以正確的刪除歸檔和 FLASHBACK,不過切記,ORACLE歸檔日誌對於O

RMAN刪除歸檔日誌不釋放問題解決

一套Oracle 11g資料庫使用RMAN沒辦法刪除舊的歸檔,導致磁碟使用率很高。 [email protected]:[/opt/oracle/archive/db] ls -ltr |more total 3059881082  -rw-r-----  1

Oracle Rac 開啟歸檔日誌並修改歸檔路徑

一、開啟歸檔日誌: 1、檢視歸檔狀態: SQL> archive log list; Database log mode           No Archive Mode Automatic archival           Disabled Archive

Oracle RMAN異機恢復歸檔RMAN-07518(供日誌挖掘使用)及修改dbid步驟

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Jul 16 15:35:06 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Windows平臺使用RMAN命令自動刪除Oracle過期歸檔日誌的方法

自動刪除Oracle過期歸檔日誌的思路如下: 1、編寫自動執行的bat指令碼檔案; 2、Windows設定定期執行計劃 OracleArchLogClear.bat D:/Oracle/produ

Oracle Database 12c RMAN全量+增量備份+歸檔日誌恢復詳解

Oracle可以非常方便的把資料庫恢復到具體某個時間的狀態,而且還支援全備和多級增備,備份無需停止應用服務。比起DB2需要手動逐級恢復增量備份和歸檔日誌,RMAN是非常簡單好用的資料庫商業解決方案。下面是我的環境:作業系統:CentOS 6.7Oracle版本:Oracle

oracle數據庫連接時提示ora-00257錯誤,提示數據庫歸檔日誌歸檔失敗

輸入 custom sed inter server2 別名 sna mil _id 轉 http://jingyan.baidu.com/article/425e69e6b142d1be15fc16dc.html Microsoft Windows [版本 6

Oracle Logminer 分析重做日誌RedoLog和歸檔日誌ArchiveLog

cti data 格式 保存 命令 重啟 msl dba object 在實際開發過程中,有時我們很有可能需要某個表的操作痕跡,或通過記錄的SQL語句進行有目的性的數據恢復(此時POINT-IN-TIME恢復已經滿足不了更細的粒度)、或僅僅是查看;

ORACLE 歸檔日誌打開關閉方法(轉載)

後臺進程 for oracl ins pfile clas 切換 med 轉載 一 設置為歸檔方式 1 sql> archive log list; #查看是不是歸檔方式 2 sql> alter system set log_arch