Oracle 維護redo日誌

Oracle的數據庫日誌稱爲redo log,全部數據改變都記錄redo log,能夠用於修復受損的數據庫。大型數據庫都採用日誌,這樣設計的好處都是同樣的。
 
Redo日誌是分組的,一個庫至少須要兩組,默認是三組。每一個組內的redo日誌稱爲成員。默認狀況下,每一個組只有一個成員,這樣沒有冗餘性,可能形成online redo log的丟失,要提升數據的可靠性,應該爲兩個組至少配置兩個成員,交將這兩個成員分配到不一樣的磁盤上。
 
Redo日誌是輪流使用的,一個redo log滿了,LGWR會切換到下一組redo log,這種操做稱爲log switch,作log switch的同時也會作checkpoint,相應的信息還會寫入控制文件。
 
也能夠手工執行log switch或checkpoint操做
 
SQL> alter system switch logfile;
System altered.
 
SQL> alter system checkpoint;
System altered.
 
查看系統的redo log信息:
 
SQL> select group#,sequence#,bytes,members,status from v$log;
    GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS
---------- ---------- ---------- ---------- ----------------
         1          5  104857600          1 INACTIVE
         2          6  104857600          1 INACTIVE
         3          7  104857600          1 CURRENT
 
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/home/oracle/oradata/gldb/redo03.log
/home/oracle/oradata/gldb/redo02.log
/home/oracle/oradata/gldb/redo01.log
 
能夠在線添加online redo log組:
 
SQL> alter database add logfile group 4 ('/home/oracle/oradata/gldb/redo04.log') size 1m;
Database altered.
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/home/oracle/oradata/gldb/redo03.log
/home/oracle/oradata/gldb/redo02.log
/home/oracle/oradata/gldb/redo01.log
/home/oracle/oradata/gldb/redo04.log
 
能夠在線添加online redo log組成員:
 
SQL> alter database add logfile member '/home/oracle/oradata/gldb/redo01b.log' to group 1;
Database altered.
 
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/home/oracle/oradata/gldb/redo03.log
/home/oracle/oradata/gldb/redo02.log
/home/oracle/oradata/gldb/redo01.log
/home/oracle/oradata/gldb/redo04.log
/home/oracle/oradata/gldb/redo01b.log
 
在線刪除剛纔添加的組和組成員:
 
SQL> alter database drop logfile group 4;
Database altered.
 
SQL> alter database drop logfile member '/home/oracle/oradata/gldb/redo01b.log';
Database altered.
 
SQL>  select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/home/oracle/oradata/gldb/redo03.log
/home/oracle/oradata/gldb/redo02.log
/home/oracle/oradata/gldb/redo01.log
 
歸檔Redo log文件:
 
啓動日誌歸檔有兩個好處:
1,帶有歸檔日誌的數據庫備份能夠恢復到任意時間點。
2,能夠在線備份數據庫。
 
若是你的數據很重要,應該啓用歸檔日誌模式,不然數據庫損壞時極可能只能恢復到上一次備份時的狀態了。

缺省狀況下,數據庫是非歸檔日誌模式。
 
能夠用如下兩條命令檢查數據庫的歸檔日誌模式:
 
SQL> select archiver from v$instance;
ARCHIVE
-------
STOPPED
 
SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /home/oracle/product/9.2.0/dbs/arch
Oldest online log sequence     7
Current log sequence           9
 
若是啓用歸檔日誌模式將在後面數據備份章節中介紹。
相關文章
相關標籤/搜索