Oracle RMAN 清除歸檔日誌

來源:互聯網
上載者:User

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

有關閱讀本文需要的相關參考

Oracle 歸檔日誌

Oracle 控制檔案(CONTROLFILE)

Oracle 聯機重做記錄檔(ONLINE LOG FILE)

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

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.