redo log file
1 . 紀錄對資料庫中的資料所作的所有更改(紀錄指令)。
2 . 用來提供恢復機制
3 . 以group為單位,每個group最少一個member(redo log file)。
4 . 至少需要有兩個group
5 . 若為RAC架構,則為多Instance對一個資料庫,redo log 則以thread對應Instance。
LGWR write redo時機
1 . 當transaction commits.
2 . 每三秒
3 . 當redo log buffer 1/3滿。
4 . 先寫redo,再把資料寫到data file。
切換redo log file的指令
alter system switch logfile;
log status觀察
SQL> select group#,thread#,sequence#,status from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
------ ------- ---------- ---------- -------- --- --------- ------------- ----------
1 1 503595 10485760 1 YES INACTIVE 2625981960 31-MAY-07
2 1 503596 10485760 1 NO CURRENT 2626024767 31-MAY-07
3 1 503594 10485760 1 YES INACTIVE 2625936142 31-MAY-07
CURRENT 正在使用狀態
INCATIVE 已經checkpoint或archived,資料可以被覆蓋
ACTIVE 資料有效,不可被覆蓋,dirty buffer 還沒寫到datafile。
check point 將 db buffer cache 的 dirty buffer寫到 datafile,checkpoint後才會是incative狀態。
- FAST_START_MTTR_TARGET = 600
(0 ~ 3600) 強制DBWR將dirty buffer寫到 datafile的秒數。
- ALTER SYSTEM CHECKPOINT
增加群組
SQL> alter database add logfile group 4 '$ORACLE_BASE/oradata/orcl/redo4.log' size 100M;
增加成員
SQL> alter database add logfile member '$ORACLE_BASE/oradata/orcl/redo4-1.log' to group 4;
刪除群組(INACTIVE狀態才可刪除)
SQL> alter database drop logfile group 1;
刪除成員(不會真的刪除,只消除在control file 紀錄)
SQL> alter database drop logfile member '$ORACLE_BASE/oradata/orcl/redo4-1.log';
Relocate and Rename (Redo log file 搬移或重新命名)
方法一 須關閉資料庫
1 . shutdown immediate
2 . 複製redo log file 到新的目錄
3 . 開啟資料庫到 mount 模式
4 . alter database rename file '/u02/oradb/oradata/orcl/redo.log'
to '/u03/oradb/oradata/orcl/redo.log'
5 . alter database open
方法二 不需關閉資料庫
Add new members and drop old members
初始化redo log file (reinitialize),用於redo檔案損毀,儘量避免使用。
alter database clear logfile group 2;
使某一group不做archived,用於redo檔案損毀,儘量避免使用。
alter database clear unzrchived logfile group2;
redo log file 的 view
v$log 從control file取出,redo lof file的資訊。
v$logfile Identifies redo log groups and members and member status
v$log_history Contains log history information
個案練習:
現狀Online Redo logs size為每個Group 10M , 欲調整為每個Group 100M。
以system使用者登入Oracle SQL*Plus
現狀:
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
------ ------- ---------- ---------- -------- --- --------- ------------- ----------
1 1 503595 10485760 1 YES INACTIVE 2625981960 31-MAY-07
2 1 503596 10485760 1 NO CURRENT 2626024767 31-MAY-07
3 1 503594 10485760 1 YES INACTIVE 2625936142 31-MAY-07
SQL> alter database add logfile group 4 '/vol1/oracle/redo04baan_1.log' size 100M;
SQL> alter database add logfile group 5 '/vol1/oracle/redo05baan_1.log' size 100M;
將目前使用的Online Redo Log切換到剛剛所新增的Redo log group
SQL> alter system switch logfile;
SQL> alter system switch logfile;
檢查是否已經切換至剛剛新增的Online Redo log group:
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
------ ------- ---------- ---------- -------- --- --------- ------------- ----------
1 1 503595 10485760 1 YES INACTIVE 2625981960 31-MAY-07
2 1 503596 10485760 1 YES INACTIVE 2626024767 31-MAY-07
3 1 503594 10485760 1 YES INACTIVE 2625936142 31-MAY-07
4 1 503597 104857600 1 YES INACTIVE 2625981970 31-MAY-07
5 1 503598 104857600 1 NO CURRENT 2626024780 31-MAY-07
刪除欲更改大小的Online Redo Logs。
SQL> alter database drop logfile group 1;
SQL> alter database drop logfile group 2;
SQL> alter database drop logfile group 3;
新增 group 1, group 2 , group 3
SQL> alter database add logfile group 1 ('/vol1/oracle/redobaan01.log') size 100M;
SQL> alter database add logfile group 2 ('/vol1/oracle/redobaan02.log') size 100M;
SQL> alter database add logfile group 3 ('/vol1/oracle/redobaan03.log') size 100M;
將目前使用的Online Redo Log切換到剛剛所新增的Redo log group
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> alter system switch logfile;
刪除過渡時期的Online Redo Logs。
SQL> alter database drop logfile group 4;
SQL> alter database drop logfile group 5;
刪除剛剛新增的過渡實體檔案(ex.redobaan04_1.log, redobaan05_1.log)
檢查調整後的結果:
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
------ ------- ---------- ---------- -------- --- --------- ------------- ----------
1 1 503599 104857600 1 YES INACTIVE 2625981960 31-MAY-07
2 1 503600 104857600 1 YES INACTIVE 2626024767 31-MAY-07
3 1 503601 104857600 1 NO CURRENT 2625936142 31-MAY-07
No comments:
Post a Comment