open階段的一致性檢驗,open一致性檢驗

來源:互聯網
上載者:User

open階段的一致性檢驗,open一致性檢驗
oracle在open階段時,需要進行一致性檢驗,然後才可以開啟資料庫,到底做了哪些檢驗呢?
首先會檢查資料檔案頭的Checkpoint CNT是否與對應的控制檔案中的Checkpoing CNT一致,如果相等,則會接下來的檢驗
然後檢查資料檔案頭的開始SCN和對應控制檔案中的結束SCN是否一致,如果結束SCN等於開始SCN,則不需要對那個資料檔案恢複
下面會通過轉儲分析控制檔案和1號資料檔案:
SQL> select * from v$version where rownum=1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
SQL> startup force mount;
ORACLE 常式已經啟動。
Total System Global Area  422670336 bytes
Fixed Size                  1336960 bytes
Variable Size             360712576 bytes
Database Buffers           54525952 bytes
Redo Buffers                6094848 bytes
資料庫裝載完畢。
SQL>  alter session set events 'immediate trace name controlf level 8';

會話已更改。

SQL> select value from v$diag_info where name='Default Trace File';

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orcl3939/orcl3939/trace/orcl3939_ora_8858.trc


***************************************************************************
DATABASE ENTRY
***************************************************************************
 (size = 316, compat size = 316, section max = 1, section in-use = 1,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 1, numrecs = 1)
 09/28/2014 17:41:29
 DB Name "ORCL3939"
 Database flags = 0x00404001 0x00001200
 Controlfile Creation Timestamp  09/28/2014 17:41:31
 Incmplt recovery scn: 0x0000.00000000
 Resetlogs scn: 0x0000.000b8338 Resetlogs Timestamp  09/28/2014 17:41:34
 Prior resetlogs scn: 0x0000.00000001 Prior resetlogs Timestamp  08/13/2009 23:00:48
 Redo Version: compatible=0xb200000
 #Data files = 10, #Online files = 10
 Database checkpoint: Thread=1 scn: 0x0000.0076948a
 Threads: #Enabled=1, #Open=0, Head=0, Tail=0
 enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
  ....
 ....
 Max log members = 3, Max data members = 1
 Arch list: Head=3, Tail=3, Force scn: 0x0000.00746fa2scn: 0x0000.00768ce3
 Activation ID: 3848061321
 Controlfile Checkpointed at scn:  0x0000.00768dc1 05/05/2015 12:24:31
 thread:0 rba:(0x0.0.0)
 enabled  threads:  00000000 00000000 00000000 00000000 00000000 00000000
 ....
....
 
***************************************************************************
DATA FILE RECORDS
***************************************************************************
 (size = 520, compat size = 520, section max = 100, section in-use = 13,
  last-recid= 2877, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 11, numrecs = 100)
DATA FILE #1: 
  name #7: /u01/app/oracle/oradata/orcl3939/system01.dbf
creation size=0 block size=8192 status=0xe head=7 tail=7 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:1110 scn: 0x0000.0076948a 05/05/2015 12:41:20
 Stop scn: 0x0000.0076948a 0
5/05/2015 12:41:20
 Creation Checkpointed at scn:  0x0000.00000007 08/13/2009 23:00:53
 thread:0 rba:(0x0.0.0)
 enabled  threads:  00000000 00000000 00000000 00000000 00000000 00000000
  ....
 ....
 Offline scn: 0x0000.000b8337 prev_range: 0
 Online Checkpointed at scn:  0x0000.000b8338 09/28/2014 17:41:34
 thread:1 rba:(0x1.2.0)
 enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
  ....
 ....
 Hot Backup end marker scn: 0x0000.00000000
 aux_file is NOT DEFINED 
 Plugged readony: NO
 Plugin scnscn: 0x0000.00000000
 Plugin resetlogs scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Foreign creation scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Foreign checkpoint scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Online move state: 0





SQL> alter session set events 'immediate trace name file_hdrs level 10';
會話已更改。
SQL>  select value from v$diag_info where name='Default Trace File';

VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orcl3939/orcl3939/trace/orcl3939_ora_8858.trc

DATA FILE #1: 
  name #7: /u01/app/oracle/oradata/orcl3939/system01.dbf
creation size=0 block size=8192 status=0xe head=7 tail=7 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:1110 scn: 0x0000.0076948a 05/05/2015 12:41:20
 Stop scn: 0x0000.0076948a 05/05/2015 12:41:20
 Creation Checkpointed at scn:  0x0000.00000007 08/13/2009 23:00:53
 thread:0 rba:(0x0.0.0)
 enabled  threads:  00000000 00000000 00000000 00000000 00000000 00000000
 ....
....
 Offline scn: 0x0000.000b8337 prev_range: 0
 Online Checkpointed at scn:  0x0000.000b8338 09/28/2014 17:41:34
 thread:1 rba:(0x1.2.0)
 enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
 ....
....
 Hot Backup end marker scn: 0x0000.00000000
 aux_file is NOT DEFINED 
 Plugged readony: NO
 Plugin scnscn: 0x0000.00000000
 Plugin resetlogs scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Foreign creation scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Foreign checkpoint scn/timescn: 0x0000.00000000 01/01/1988 00:00:00
 Online move state: 0
上面的資訊來自控制檔案
下面的資訊來自資料檔案頭(如果資料檔案丟失,則資料檔案頭不能讀取)
 V10 STYLE FILE HEADER:
Compatibility Vsn = 186646528=0xb200000
Db ID=3848072073=0xe55ceb89, Db Name='ORCL3939'
Activation ID=0=0x0
Control Seq=14952=0x3a68, File size=96000=0x17700
File Number=1, Blksiz=8192, File Type=3 DATA
Tablespace #0 - SYSTEM  rel_fn:1 
Creation   at   scn: 0x0000.00000007 08/13/2009 23:00:53
Backup taken at scn: 0x0000.00713a30 04/29/2015 13:41:44 thread:1
 reset logs count:0x333ab14e scn: 0x0000.000b8338
 prev reset logs count:0x296a3120 scn: 0x0000.00000001
 recovered at 05/05/2015 12:24:15
 status:0x2000 root dba:0x00400208 chkpt cnt: 1110 ctl cnt:1109
begin-hot-backup file size: 96000
Checkpointed at scn:  0x0000.0076948a 05/05/2015 12:41:20
 thread:1 rba:(0x1ce.1314.10)
 enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
 ....
 ....
Backup Checkpointed at scn:  0x0000.00713a30 04/29/2015 13:41:44
 thread:1 rba:(0x1bd.b6c8.10)
 enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
  ....
 ....

首先會檢查資料檔案頭的Checkpoint CNT是否與對應的控制檔案中的Checkpoing CNT一致:
由上知控制檔案中記錄了chkpt cnt 1110    資料檔案頭記錄了chkpt  cnt 1110    ctl cnt 1109
為什麼資料檔案頭的chkpt  cnt 比 ctl cnt大1呢,這是因為檢查點在更新控制檔案和資料檔案頭上的chkpt cnt時,可以獲得當前的ctl cnt,把當前的ctl cnt 寫入到了資料檔案頭,即1109
這一步驗證已經通過
然後檢查資料檔案頭的開始SCN和對應控制檔案中的結束SCN是否一致:
Checkpointed at scn:  0x0000.0076948a   05/05/2015 12:41:20
兩者一致,可以正常啟動
控制檔案記錄的scn 是資料庫最後一次成功完成檢查點的scn,資料檔案頭記錄的scn  是最後一次完成檢查點的scn,兩者相等,則不需要對你資料檔案進行恢複,如果不一致,則需要對資料檔案

進行恢複。假如資料庫異常關閉後,資料檔案頭記錄的scn比較舊,與控制檔案記錄的不一致,則需要進行恢複,並且資料檔案頭記錄的scn是恢複的起點

SQL> shutdown immediate;
資料庫已經關閉。
已經卸載資料庫。
ORACLE 常式已經關閉。
SQL> startup mount;
ORACLE 常式已經啟動。
Total System Global Area  422670336 bytes
Fixed Size                  1336960 bytes
Variable Size             360712576 bytes
Database Buffers           54525952 bytes
Redo Buffers                6094848 bytes
資料庫裝載完畢。
SQL> select file#,checkpoint_change# from v$datafile;


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7771815
         2            7771815
         3            7771815
         4            7771815
         5            7771815
         7            7771815
         8            7771815
         9            7771815
        11            7771815
        12            7771815


已選擇10行。


SQL> select file#,checkpoint_change# from v$datafile_header;


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7771815
         2            7771815
         3            7771815
         4            7771815
         5            7771815
         7            7771815
         8            7771815
         9            7771815
        11            7771815
        12            7771815

已選擇10行。

上面兩者是相等的,沒有問題,讀者可以類比需要恢複案例。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.