【REDO】重做日誌檔案(redo log files)管理(增,刪,改,查,切)

secooler發表於2009-03-09
彙總整理一下有關重做日誌檔案(redo log files)管理相關的操作(增,刪,改,查,切)。供參考。

1.當前日誌相關資訊

sys@ora11g> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS    FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
         1          1         10  209715200          1 YES INACTIVE         461938 09-MAR-09
         2          1         11  209715200          1 NO  CURRENT          485885 09-MAR-09
         3          1          9  209715200          1 YES INACTIVE         432636 04-MAR-09

sys@ora11g> select * from v$logfile;

    GROUP# STATUS  TYPE                 MEMBER                                   IS_
---------- ------- -------------------- ---------------------------------------- ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01.log    NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02.log    NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03.log    NO

2.新增重做日誌組
sys@ora11g> alter database add logfile group 4 ('/oracle/u02/oradata/ora11g/redo04_01.log','/oracle/u02/oradata/ora11g/redo04_02.log') size 50m;

Database altered.

sys@ora11g> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS    FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
         1          1         10  209715200          1 YES INACTIVE         461938 09-MAR-09
         2          1         11  209715200          1 NO  CURRENT          485885 09-MAR-09
         3          1          9  209715200          1 YES INACTIVE         432636 04-MAR-09
         4          1          0   52428800          2 YES UNUSED                0

sys@ora11g> select * from v$logfile;

    GROUP# STATUS  TYPE                 MEMBER                                   IS_
---------- ------- -------------------- ---------------------------------------- ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01.log    NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02.log    NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03.log    NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_01.log NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_02.log NO


3.新增日誌檔案
sys@ora11g> alter database add logfile member
             '/oracle/u02/oradata/ora11g/redo01_02.log' to group 1,
             '/oracle/u02/oradata/ora11g/redo02_02.log' to group 2,
             '/oracle/u02/oradata/ora11g/redo03_02.log' to group 3;

Database altered.

sys@ora11g> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS    FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
         1          1         10  209715200          2 YES INACTIVE         461938 09-MAR-09
         2          1         11  209715200          2 NO  CURRENT          485885 09-MAR-09
         3          1          9  209715200          2 YES INACTIVE         432636 04-MAR-09
         4          1          0   52428800          2 YES UNUSED                0

sys@ora11g>  select * from v$logfile order by 1;

    GROUP# STATUS  TYPE                 MEMBER                                   IS_
---------- ------- -------------------- ---------------------------------------- ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01.log    NO
         1 INVALID ONLINE               /oracle/u02/oradata/ora11g/redo01_02.log NO
         2 INVALID ONLINE               /oracle/u02/oradata/ora11g/redo02_02.log NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02.log    NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03.log    NO
         3 INVALID ONLINE               /oracle/u02/oradata/ora11g/redo03_02.log NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_02.log NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_01.log NO

8 rows selected.

4.重新命名日誌成員
在重新命名日誌組成員之前新的目標必須已經存在。Oracle的sql命令只是把控制檔案中的內部指標指向新的日誌檔案。
1)關閉資料庫

sys@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

2)使用作業系統命令重新命名或移動日誌檔案
ora11g@RHEL53 /oracle/u02/oradata/ora11g$ mv redo01.log redo01_01.log
ora11g@RHEL53 /oracle/u02/oradata/ora11g$ mv redo02.log redo02_01.log
ora11g@RHEL53 /oracle/u02/oradata/ora11g$ mv redo03.log redo03_01.log

3)啟動資料庫例項到mount狀態,重新命名控制檔案中的日誌檔案成員。
NotConnected@> select * from v$logfile order by 1,4;

    GROUP# STATUS  TYPE                 MEMBER                                     IS_
---------- ------- -------------------- ------------------------------------------ ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01.log      NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02.log      NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03.log      NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_01.log   NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_02.log   NO
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_02.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_02.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_02.log   NO

8 rows selected.

NotConnected@> alter database rename file '/oracle/u02/oradata/ora11g/redo01.log' to '/oracle/u02/oradata/ora11g/redo01_01.log';

Database altered.

NotConnected@> alter database rename file '/oracle/u02/oradata/ora11g/redo02.log' to '/oracle/u02/oradata/ora11g/redo02_01.log';

Database altered.

NotConnected@> alter database rename file '/oracle/u02/oradata/ora11g/redo03.log' to '/oracle/u02/oradata/ora11g/redo03_01.log';

Database altered.

4)open資料庫,驗證結果
NotConnected@> alter database open;

Database altered.

sys@ora11g> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS   FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- -------- ------------- ---------
         1          1         18  209715200          2 YES INACTIVE        486960 09-MAR-09
         2          1         19  209715200          2 YES INACTIVE        486964 09-MAR-09
         3          1         21  209715200          2 NO  CURRENT         486973 09-MAR-09
         4          1         20   52428800          2 YES INACTIVE        486968 09-MAR-09

sys@ora11g> select * from v$logfile order by 1,4;

    GROUP# STATUS  TYPE                 MEMBER                                     IS_
---------- ------- -------------------- ------------------------------------------ ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_01.log   NO
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_02.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_01.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_02.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_01.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_02.log   NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_01.log   NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_02.log   NO

8 rows selected.

5)最後,不要忘記備份控制檔案
sys@ora11g> alter database backup controlfile to trace;

Database altered.

5.刪除一個非活動的重做日誌組的成員
sys@ora11g> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS   FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- -------- ------------- ---------
         1          1         18  209715200          2 YES INACTIVE        486960 09-MAR-09
         2          1         19  209715200          2 YES INACTIVE        486964 09-MAR-09
         3          1         21  209715200          2 NO  CURRENT         486973 09-MAR-09
         4          1         20   52428800          2 YES INACTIVE        486968 09-MAR-09

sys@ora11g> alter database drop logfile member '/oracle/u02/oradata/ora11g/redo04_02.log';

Database altered.

sys@ora11g> !ls -l /oracle/u02/oradata/ora11g/redo04_02.log
-rw-r----- 1 oracle oinstall 52429312 Mar  9 16:28 /oracle/u02/oradata/ora11g/redo04_02.log

sys@ora11g> !rm -f /oracle/u02/oradata/ora11g/redo04_02.log

sys@ora11g> select * from v$logfile order by 1,4;

    GROUP# STATUS  TYPE                 MEMBER                                     IS_
---------- ------- -------------------- ------------------------------------------ ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_01.log   NO
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_02.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_01.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_02.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_01.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_02.log   NO
         4         ONLINE               /oracle/u02/oradata/ora11g/redo04_01.log   NO

7 rows selected.

6.刪除一個非活動的重做日誌組
sys@ora11g> alter database drop logfile group 4;

Database altered.

sys@ora11g> !rm -f /oracle/u02/oradata/ora11g/redo04_01.log

sys@ora11g> select * from v$logfile;

    GROUP# STATUS  TYPE                 MEMBER                                     IS_
---------- ------- -------------------- ------------------------------------------ ---
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_01.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_01.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_01.log   NO
         1         ONLINE               /oracle/u02/oradata/ora11g/redo01_02.log   NO
         2         ONLINE               /oracle/u02/oradata/ora11g/redo02_02.log   NO
         3         ONLINE               /oracle/u02/oradata/ora11g/redo03_02.log   NO

6 rows selected.

7.強制切換日誌
sys@ora11g> alter system switch logfile;

System altered.

sys@ora11g> alter system archive log current;

System altered.

8.小結
1)日誌檔案非常重要,當多路複用重做日誌檔案時,應該把一個組的成員儲存在不同的磁碟上。
2
在完成日誌檔案維護後一定要記得備份最新的控制檔案!
3
以上試驗是在11g環境下完成的,在10g環境中一樣適用。

Good luck.

secooler
09.03.09

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-566453/,如需轉載,請註明出處,否則將追究法律責任。

相關文章