16、重做日誌檔案的狀態及重做日誌組的狀態說明

yyycxhtx發表於2007-08-03
重做日誌檔案和重做日誌組的狀態[@more@]

一、日誌檔案的狀態包括:

1、NULL -File is in use

2、STALE-contents of the file are incomplete

3、INVALID-File is inaccessible

4、DELETED-File is no longer used

二、重做日誌組的狀態包括:

1、CURRENT-Current redo log.This implies that the redo log is active.The redo log could be open or closed.

2、UNUSED-Online redo log has never been written to.This is the status of a redo log that was just added.or just after a RESETLOGS.when it is not the current redo log

3、ACTIVE- Log is active but is not the current log. It is needed for crash recovery. It may be in use for block recovery. It may or may not be archived

4、INACTIVE-Log is no longer needed for instance recovery. It may be in use for media recovery. It might or might not be archived.

5、CLEARING-這個日誌正在被重建,重建後為空的日誌,當日志被cleared後,狀態變為unused,使用alter data clear logfile 可以進行重建操作

6、CALERING_CURRENT-對於一個關閉的thread,重建當前日誌,當日志撤換過程中在寫新的重做日誌時發生i/o錯誤出現錯誤的會出現這種狀態的重做日誌

三、狀態變化過程及應用

SQL> alter database clear logfile group 1;

資料庫已更改。

SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 0 UNUSED YES --執行clear命令後,狀態為unused
2 173 CURRENT NO
3 171 INACTIVE YES

SQL> drop table t;

表已丟棄。

SQL> create table t as select * from dba_objects;

表已建立。

SQL> insert into t select * from t;

已建立25745行。

SQL> insert into t select * from t;

已建立51490行。

SQL> insert into t select * from t;

已建立102980行。

SQL> insert into t select * from t;

已建立205960行。

SQL> insert into t select * from t;

已建立411920行。

SQL> insert into t select * from t;

已建立823840行。

SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 174 INACTIVE YES
2 176 CURRENT NO --活動且當前
3 175 ACTIVE NO --活動

SQL> commit;

提交完成。

SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 174 INACTIVE YES
2 176 CURRENT NO
3 175 INACTIVE YES --提交後發現已經歸檔

SQL> insert into t select * from t;

已建立1647680行。

SQL> alter system switch logfile;

系統已更改。

SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 177 ACTIVE NO
2 176 ACTIVE YES
3 178 CURRENT NO

--幾秒之後
SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 177 INACTIVE YES --發現歸檔了,並且狀態變為inactive
2 179 CURRENT NO
3 178 ACTIVE YES

--此時非正常關閉
--那麼需要例程恢復,看看應用到那些線上重做日誌
SQL> shutdown abort;
ORACLE 例程已經關閉。
SQL> startup mount;
ORACLE 例程已經啟動。

Total System Global Area 319888364 bytes
Fixed Size 453612 bytes
Variable Size 192937984 bytes
Database Buffers 125829120 bytes
Redo Buffers 667648 bytes
資料庫裝載完畢。
SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 177 INACTIVE YES
2 179 CURRENT NO
3 178 ACTIVE YES

--開啟資料庫
SQL> alter database open;

資料庫已更改。

--檢視alert日誌
ALTER DATABASE MOUNT
Sun May 21 09:33:29 2006
Successful mount of redo thread 1, with mount id 1184869413.
Sun May 21 09:33:29 2006
Database mounted in Exclusive Mode.
Completed: ALTER DATABASE MOUNT
Sun May 21 09:35:47 2006
alter database open
Sun May 21 09:35:47 2006
Beginning crash recovery of 1 threads
Sun May 21 09:35:47 2006
Started first pass scan
Sun May 21 09:35:49 2006
Completed first pass scan
112893 redo blocks read, 7011 data blocks need recovery
Sun May 21 09:35:50 2006
Started recovery at
Thread 1: logseq 178, block 159334, scn 0.0 --發現會用到這個在序號為178,因為是active
Recovery of Online Redo Log: Thread 1 Group 3 Seq 178 Reading mem 0
Mem# 0 errs 0: D:ORACLEORADATADB1REDO03.LOG
Recovery of Online Redo Log: Thread 1 Group 2 Seq 179 Reading mem 0
Mem# 0 errs 0: D:ORACLEORADATADB1REDO02.LOG
Sun May 21 09:35:53 2006
Ended recovery at
Thread 1: logseq 179, block 67445, scn 0.5728855 --179也會用到,因為當前肯定是active的
7011 data blocks read, 7011 data blocks written, 112893 redo blocks read
Crash recovery completed successfully
Sun May 21 09:35:53 2006
LGWR: Primary database is in CLUSTER CONSISTENT mode
Thread 1 advanced to log sequence 180
Thread 1 opened at log sequence 180
Current log# 1 seq# 180 mem# 0: D:ORACLEORADATADB1REDO01.LOG
Successful open of redo thread 1.
Sun May 21 09:35:53 2006
SMON: enabling cache recovery
Sun May 21 09:35:53 2006
ARC0: Evaluating archive log 2 thread 1 sequence 179
ARC0: Beginning to archive log 2 thread 1 sequence 179
Creating archive destination LOG_ARCHIVE_DEST_1: 'D:DBBKARC00179.001'
Sun May 21 09:35:55 2006
Undo Segment 1 Onlined
Undo Segment 2 Onlined
Undo Segment 3 Onlined
Undo Segment 4 Onlined
Undo Segment 5 Onlined
Undo Segment 6 Onlined
Undo Segment 7 Onlined
Undo Segment 8 Onlined
Undo Segment 9 Onlined
Undo Segment 10 Onlined
Successfully onlined Undo Tablespace 1.
Sun May 21 09:35:55 2006
SMON: enabling tx recovery
Sun May 21 09:35:56 2006
Database Characterset is ZHS16GBK
Sun May 21 09:35:58 2006
ARC0: Completed archiving log 2 thread 1 sequence 179
Sun May 21 09:36:01 2006
replication_dependency_tracking turned off (no async multimaster replication found)
Completed: alter database open

--此過程會應用到日誌序號為178,179的兩個重做日誌序號,並且把日誌序號加1置為新的current狀態,把

--之前current狀態的序號進行歸檔,然後才開啟資料庫。
--查詢後看到序號最新的已經是180了,並且之前的日誌都已經歸檔。
SQL> select group#,sequence#,status,archived from v$log;

GROUP# SEQUENCE# STATUS ARC
---------- ---------- ---------------- ---
1 180 CURRENT NO
2 179 INACTIVE YES
3 178 INACTIVE YES

--檢視未提交的記錄,發現已經回滾
SQL> select count(*) from t;

COUNT(*)
----------
1647680

四、關於stale狀態的說明

A stale redo log file is one that Oracle believes might be incomplete for some reason. This typically happens when a temporary error prevents the LGWR background process from writing to a redo log group member.

If Oracle cannot write to a redo log file at any one time, that log file can no longer be trusted, and Oracle marks it as "STALE". This indicates that the log file cannot be relied upon to provide all the data written to the log.
Here is the recommended procedure to deal with a stale redo log:
1. Issue the following query:
SELECT V2.GROUP#, MEMBER, V2.STATUS MEMBER_STATUS,
V1.STATUS GROUP_STATUS
FROM V$LOG V1, V$LOGFILE V2
WHERE V1.GROUP# = V2.GROUP# AND V2.STATUS = 'STALE';
This will show you the group status for all stale log files.
2. For each stale log file,
2.a) If the GROUP_STATUS is 'INACTIVE', do nothing.
That implies Oracle has already checkpointed past that redo group, and thus its contents are no longer needed for instance recovery.
Once the redo group becomes current again, the stale status of
the log file will go away by itself.
2.b) If the GROUP_STATUS is 'ACTIVE', go back to Step 1 and repeat
the query a few more times.
This status usually means that the log group is no longer the current one, but the corresponding checkpoint has not completed yet. Unless there is a problem, the log group should become inactive shortly.
2.c) If the GROUP_STATUS is 'CURRENT', force a log switch now.
ALTER SYSTEM SWITCH LOGFILE;
This will also force a checkpoint. If the checkpoint completes successfully, the contents of the redo group are no longer needed for instance recovery. Go back to Step 1 and repeat the query a few more times until the log group becomes inactive.
IMPORTANT: If the stale logfile belongs to an active group or the current group (cases 2.b and 2.c above), DO NOT ISSUE A SHUTDOWN ABORT UNTIL THE GROUP BECOMES INACTIVE.
3. Investigate the extent of the problem.
Examine the alert.log file for this instance and the LGWR
trace file, if one can be found in your background_dump_dest.
See if there is any pattern to the problem. Do you see any
recent errors, such as ORA-312, referencing that particular log
file? If so, there may be some corruption problem with the file
or a problem with the I/O subsystem (disk, controllers, etc.) .
If you are running any other Oracle version on any other platform
If there is no pattern to the problem, it is more likely an
isolated incident.
4. If you are archiving, make sure the log has been correctly archived.
Before archiving a redo log group, the ARCH process actually
verifies that its contents are valid. If that is not the case,
it issues an error such as ORA-255 ("error archiving log %s
of thread %s, sequence # %s"). Therefore, if the log group to
which the stale member belongs has been successfully archived,
it means the redo contents of the group are good, and that
archived log can be safely used for recovery. ARCH errors, if
any, will be reported in your alert.log file and in an ARCH
trace file.

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

相關文章