判斷資料庫是否需要例項恢復
[root@vmrac1 ~]# su - oracle
[oracle@vmrac1 ~]$ sqlplus / as sysdba
-- system checkpoint SCN
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1330820
-- datafile checkpoint SCN
SQL> select checkpoint_change# from v$datafile;
CHECKPOINT_CHANGE#
------------------
1332188
1332188
1332188
1332188
1332188
1332188
6 rows selected.
-- Start SCN
SQL> select checkpoint_change# from v$datafile_header;
CHECKPOINT_CHANGE#
------------------
1332188
1332188
1332188
1332188
1332188
1332188
6 rows selected.
-- End SCN
SQL> col name for a50
SQL> select name,last_change# from v$datafile;
NAME LAST_CHANGE#
-------------------------------------------------- ------------
+DATA/rac/datafile/system.256.829110499
+DATA/rac/datafile/sysaux.257.829110501
+DATA/rac/datafile/undotbs1.258.829110501
+DATA/rac/datafile/users.259.829110501
+DATA/rac/datafile/example.267.829110655
+DATA/rac/datafile/undotbs2.268.829111091
6 rows selected.
-- duration database running End SCN is null
SQL> select name,fuzzy from v$datafile_header;
NAME FUZ
-------------------------------------------------- ---
+DATA/rac/datafile/system.256.829110499 YES
+DATA/rac/datafile/sysaux.257.829110501 YES
+DATA/rac/datafile/undotbs1.258.829110501 YES
+DATA/rac/datafile/users.259.829110501 YES
+DATA/rac/datafile/example.267.829110655 YES
+DATA/rac/datafile/undotbs2.268.829111091 YES
6 rows selected.
SQL> select thread#,sequence#,first_change#,next_change# from v$log order by 1,2;
THREAD# SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ------------- ------------
1 8 1174330 1263670
1 9 1263670 2.8147E+14
2 4 1232702 1283679
2 5 1283679 1330825
SQL> alter system checkpoint;
System altered.
SQL> select checkpoint_change# from v$datafile_header;
CHECKPOINT_CHANGE#
------------------
1335465
1335465
1335465
1335465
1335465
1335465
6 rows selected.
SQL> select checkpoint_change#,last_change# from v$datafile;
CHECKPOINT_CHANGE# LAST_CHANGE#
------------------ ------------
1335465
1335465
1335465
1335465
1335465
1335465
6 rows selected.
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1335465
SQL> select thread#,sequence#,first_change#,next_change# from v$log order by 1,2;
THREAD# SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ------------- ------------
1 8 1174330 1263670
1 9 1263670 2.8147E+14
2 4 1232702 1283679
2 5 1283679 1330825
-- case
-- when a.checkpoint_change# = b.checkpoint_change#
-- then 'startup normal'
-- when a.checkpoint_change# > b.checkpoint_change#
-- then 'media recovery'
-- when a.checkpoint_change# < b.checkpoint_change#
-- then 'old control file'
-- from v$datafile a #controlfile SCN for datafile
-- v$datafile_header b #datafile_header SCN
-- 通過以下儲存過程直接查詢
SQL> grant select on v_$datafile to scott;
Grant succeeded.
SQL> grant select on v_$datafile_header to scott;
Grant succeeded.
SQL> create or replace procedure recover_state as
result varchar2(100);
num number(10);
begin
select a.checkpoint_change#-b.checkpoint_change# into num from sys.v_$datafile a,sys.v_$datafile_header b where a.file#=b.file# and a.file#=
1;
result:=
case
when num=0 then ('Instance Startup Normal.')
when num>0 then ('Need Media Recovery.')
else ('Old Controlfile.')
end;
dbms_output.put_line(result);
end;
/
Procedure created.
SQL> set serveroutput on
SQL> execute recover_state;
Instance Startup Normal.
PL/SQL procedure successfully completed.
SQL> col instance for a20
SQL> select thread#,status,enabled,instance,open_time,checkpoint_change# from v$thread;
THREAD# STATUS ENABLED INSTANCE OPEN_TIME CHECKPOINT_CHANGE#
---------- ------ -------- -------------------- ------------ ------------------
1 OPEN PUBLIC rac1 28-OCT-13 1335465
2 CLOSED PUBLIC rac2 27-OCT-13 1317632
-- check v$thread.status at database mount stage
-- select a.thread#,b.open_mode,a.status
-- case
-- when b.open_mode='mounted' and a.status='open'
-- then 'crash recovery Request.'
-- when b.open_mode='mounted' and a.status='closed'
-- then 'no crash Recocvery Request.'
-- when b.open_mode='read write' and a.status='open'
-- then 'Instance already open.'
-- end status
-- from v$thread# a,v$database b,v$instance c
-- where a.thread#=c.thread#
SQL> select a.thread#,b.open_mode,a.status from v$thread a,v$database b,v$instance c where a.thread#=c.thread#;
THREAD# OPEN_MODE STATUS
---------- -------------------- ------
1 READ WRITE OPEN
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 463478784 bytes
Fixed Size 2229384 bytes
Variable Size 213912440 bytes
Database Buffers 239075328 bytes
Redo Buffers 8261632 bytes
Database mounted.
-- no crash recovery request like below
SQL> select a.thread#,b.open_mode,a.status from v$thread a,v$database b,v$instance c where a.thread#=c.thread#;
THREAD# OPEN_MODE STATUS
---------- -------------------- ----------
1 MOUNTED CLOSED
SQL> alter database open;
Database altered.
-- Instance already open like below
SQL> select a.thread#,b.open_mode,a.status from v$thread a,v$database b,v$instance c where a.thread#=c.thread#;
THREAD# OPEN_MODE STATUS
---------- -------------------- ----------
1 READ WRITE OPEN
-- instance recovery is automatic run,a dba nothing to do
-- instance recovery do something
-- a.rollover from online redo log
-- b.open database
-- c.SMON or user process do rollback
例項恢復的啟動過程及所有資訊可以從alert日誌檔案中檢視。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/429786/viewspace-776896/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 判斷oracle是否是rac例項Oracle
- RAC資料庫恢復到單例項資料庫資料庫單例
- 【資料庫資料恢復】ASM例項不能掛載的Oracle資料庫資料恢復案例資料庫資料恢復ASMOracle
- 資料塊恢復例項
- 恢復RAC資料庫到單例項(ASM)資料庫單例ASM
- 【資料庫資料恢復】Oracle ASM例項無法掛載的資料恢復案例資料庫資料恢復OracleASM
- 單例項恢復RAC資料庫步驟(三)單例資料庫
- 單例項恢復RAC資料庫步驟(二)單例資料庫
- 單例項恢復RAC資料庫步驟(一)單例資料庫
- js判斷元素是否為空程式碼例項JS
- 資料庫的備份與恢復分析及例項資料庫
- js判斷文字框是否為空程式碼例項JS
- javascript判斷物件是否為空物件程式碼例項JavaScript物件
- js判斷螢幕是否旋轉程式碼例項JS
- 將RAC備份集恢復為單例項資料庫單例資料庫
- Sql Server中判斷表或者資料庫是否存在SQLServer資料庫
- java判斷mysql中資料庫是否存在JavaMySql資料庫
- jquery判斷滾動是否到達底部程式碼例項jQuery
- 判斷url連結地址是否合法的例項程式碼
- mysql資料庫恢復一例MySql資料庫
- RAC 資料庫恢復到單例項下並且基於時間點恢復資料庫單例
- 【資料庫資料恢復】斷電導致Oracle資料庫資料丟失的資料恢復案例資料庫資料恢復Oracle
- 【RAC】將單例項備份集恢復為rac資料庫單例資料庫
- 【RAC】將RAC備份集恢復為單例項資料庫單例資料庫
- 單例項環境利用備份恢復RAC資料庫(四)單例資料庫
- 單例項環境利用備份恢復RAC資料庫(三)單例資料庫
- 單例項環境利用備份恢復RAC資料庫(二)單例資料庫
- 單例項環境利用備份恢復RAC資料庫(一)單例資料庫
- catalog損壞情況下的資料庫恢復例項資料庫
- 【資料庫資料恢復】突然斷電造成Syabse資料庫無法啟動的資料恢復案例資料庫資料恢復
- 硬碟資料恢復例項全解(1) (轉)硬碟資料恢復
- js實現的判斷是否是閏年程式碼例項JS
- js判斷陣列中是否含有指定元素程式碼例項JS陣列
- jquery判斷<img>圖片是否載入完成程式碼例項jQuery
- 判斷a是否是int型別資料型別
- PHP:判斷是否是JSON資料PHPJSON
- 【資料庫資料恢復】SAP資料庫資料恢復案例資料庫資料恢復
- 【kingsql分享】將RAC資料庫異機恢復到單例項(Ⅰ)SQL資料庫單例