程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> open階段的一致性檢驗

open階段的一致性檢驗

編輯:DB2教程

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行。

上面兩者是相等的,沒有問題,讀者可以模擬需要恢復案例。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved