您的位置:首页 > 其它

关于控制文件与数据文件头信息的说明

2017-02-28 00:00 274 查看
当我们使用file_hdrs事件来转储数据文件头信息时,Oracle会转储两部分信息:一部分来自控制文件,一部分来自数据文件。在数据库启动过程中,这两部分信息要用来进行启动验证。

在数据库open的过程中,Oracle要进行检查中包含以下两个过程:

第一次检查数据文件头中的Checkpoint cnt是否与对应控制文件中的Checkpoint cnt一致.
如果相等,进行第二次检查.

第二次检查数据文件头的开始SCN和对应控制文件中的结束SCN是否一致如果结束SCN等于开始SCN,则不需要对那个文件进行恢复.

对每个数据文件都完成检查后,打开数据库.同时将每个数据文件的结束SCN设置为无穷大.

通过以下过程我们来进一步说明一下这个内容。

我们来看以下来自控制文件部分(选取一个文件测试):

DATA FILE #4:
(name #4) /opt/oracle/oradata/javis/javis01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 4, index=4 krfil=4 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:58 scn: 0x0000.002ac8ee 08/11/2006 09:48:29
Stop scn: 0x0000.002ac8ee 08/11/2006 09:48:29
Creation Checkpointed at scn:  0x0000.0015078d 06/06/2006 09:41:54
thread:0 rba:(0x0.0.0)
................
aux_file is NOT DEFINED

这部分中包含的重要信息有:
检查点计数: Checkpoint cnt:58
检查点SCN: scn: 0x0000.002ac8ee 08/11/2006 09:48:29
数据文件Stop SCN:Stop scn: 0x0000.002ac8ee 08/11/2006 09:48:29

我们再看来自数据文件头的信息:

FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1407686520=0x53e79778, Db Name='EYGLE'
Activation ID=0=0x0
Control Seq=979=0x3d3, File size=1280=0x500
File Number=4, Blksiz=8192, File Type=3 DATA
Tablespace #4 - EYGLE  rel_fn:4
Creation   at   scn: 0x0000.0015078d 06/06/2006 09:41:54
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x232bee1f scn: 0x0000.0007c781 recovered at 08/10/2006 20:57:53
status:0x0 root dba:0x00000000 chkpt cnt: 58 ctl cnt:57
begin-hot-backup file size: 0
Checkpointed at scn:  0x0000.002ac8ee 08/11/2006 09:48:29
.......................

这部分中包含的重要信息有:
检查点SCN: Checkpointed at scn: 0x0000.002ac8ee 08/11/2006 09:48:29
检查点计数: chkpt cnt: 58 ctl cnt:57

这两者都和控制文件中所记录的一致。如果这两者一致,数据库启动时就能通过验证,启动数据库。

那么如果不一致呢?
Oracle则请求进行恢复。
我们看,从备份中恢复eygle01.dbf文件.
首先第一部分从控制文件中获得的信息是相同的:

DATA FILE #4:
(name #4) /opt/oracle/oradata/javis/javis01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 4, index=4 krfil=4 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:58 scn: 0x0000.002ac8ee 08/11/2006 09:48:29
Stop scn: 0x0000.002ac8ee 08/11/2006 09:48:29
Creation Checkpointed at scn:  0x0000.0015078d 06/06/2006 09:41:54
...................
aux_file is NOT DEFINED

检查点计数: Checkpoint cnt:58
检查点SCN: scn: 0x0000.002ac8ee 08/11/2006 09:48:29
数据文件Stop SCN:Stop scn: 0x0000.002ac8ee 08/11/2006 09:48:29

而从文件头中获得的备份文件信息则是:

FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1407686520=0x53e79778, Db Name='javis'
Activation ID=0=0x0
Control Seq=973=0x3cd, File size=1280=0x500
File Number=4, Blksiz=8192, File Type=3 DATA
Tablespace #4 - javis  rel
3ff0
_fn:4
Creation   at   scn: 0x0000.0015078d 06/06/2006 09:41:54
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x232bee1f scn: 0x0000.0007c781 recovered at 08/10/2006 20:57:53
status:0x0 root dba:0x00000000 chkpt cnt: 53 ctl cnt:52
begin-hot-backup file size: 0
Checkpointed at scn:  0x0000.002ac5f9 08/10/2006 20:58:21
...................................

我们看到此时备份文件的信息:
检查点是:Checkpointed at scn: 0x0000.002ac5f9 08/10/2006 20:58:21
检查点计数为:chkpt cnt: 53 ctl cnt:52

这两者不再一致,首先是检查点技术不一致,当前文件的chkpt cnt为53,小于控制文件中记录的58,Oracle可以判断文件是从备份中恢复的,或者文件故障,需要进行介质恢复。

我们看如果此时我们试图打开数据库,则Oracle提示文件需要介质恢复:

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/opt/oracle/oradata/javis/javis01.dbf'

执行恢复:

SQL> recover datafile 4;
Media recovery complete.

我们看看恢复完成之后,控制文件和数据文件的变化.
首先看控制文件的变化:

DATA FILE #4:
(name #4) /opt/oracle/oradata/javis/javis01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 4, index=4 krfil=4 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:59 scn: 0x0000.002ac8ee 08/11/2006 09:48:29
Stop scn: 0x0000.002ac8ed 08/11/2006 09:48:29
Creation Checkpointed at scn:  0x0000.0015078d 06/06/2006 09:41:54
......................

检查点计数: Checkpoint cnt:59
执行了恢复之后,检查点计数较前增加了1

检查点SCN: scn: 0x0000.002ac8ee 08/11/2006 09:48:29
数据文件Stop scn: 0x0000.002ac8ed 08/11/2006 09:48:29
数据文件Stop scn和数据文件进行了同步。

数据文件头信息:

FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1407686520=0x53e79778, Db Name='EYGLE'
Activation ID=0=0x0
Control Seq=983=0x3d7, File size=1280=0x500
File Number=4, Blksiz=8192, File Type=3 DATA
Tablespace #4 - EYGLE  rel_fn:4
Creation   at   scn: 0x0000.0015078d 06/06/2006 09:41:54
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x232bee1f scn: 0x0000.0007c781 recovered at 08/11/2006 10:11:26
status:0x0 root dba:0x00000000 chkpt cnt: 59 ctl cnt:58
begin-hot-backup file size: 0
Checkpointed at scn:  0x0000.002ac8ed 08/11/2006 09:48:29
..........................

我们看到此时数据文件的信息:
检查点是:Checkpointed at scn: 0x0000.002ac8ed 08/11/2006 09:48:29
这个检查点和控制文件中记录的stop scn一致,数据库启动可以顺利进行。

检查点计数为:chkpt cnt: 59 ctl cnt:58

我们打开数据库:

SQL> alter database open;

Database altered.

SQL> alter session set events 'immediate trace name file_hdrs level 10';

Session altered.

此时数据库恢复正常运行。
控制文件信息如下:

DATA FILE #4:
(name #4) /opt/oracle/oradata/javis/javis01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 4, index=4 krfil=4 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:60 scn: 0x0000.002ac8ef 08/11/2006 10:19:30
Stop scn: 0xffff.ffffffff 08/11/2006 09:48:29
Creation Checkpointed at scn:  0x0000.0015078d 06/06/2006 09:41:54

此时stop scn被置为无穷大。
数据文件头信息如下:

FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1407686520=0x53e79778, Db Name='EYGLE'
Activation ID=0=0x0
Control Seq=984=0x3d8, File size=1280=0x500
File Number=4, Blksiz=8192, File Type=3 DATA
Tablespace #4 - EYGLE  rel_fn:4
Creation   at   scn: 0x0000.0015078d 06/06/2006 09:41:54
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x232bee1f scn: 0x0000.0007c781 recovered at 08/11/2006 10:11:26
status:0x4 root dba:0x00000000 chkpt cnt: 60 ctl cnt:59
begin-hot-backup file size: 0
Checkpointed at scn:  0x0000.002ac8ef 08/11/2006 10:19:30

我们可以想象,如果控制文件是从备份中恢复的,那么数据库在open过程中又将如何呢?

首先备份控制文件,打开数据库,增进检查点:

[oracle@jumper javis]$ cp control01.ctl control01.ctl.bak
[oracle@jumper javis]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Aug 11 10:46:05 2006

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  139531744 bytes
Fixed Size                   452064 bytes
Variable Size             121634816 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> alter system checkpoint;

System altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

然后恢复旧的控制文件,mount数据库,转储数据文件头:

[oracle@jumper javis]$ mv control01.ctl control01.ctl.n
[oracle@jumper javis]$ mv control01.ctl.bak control01.ctl
[oracle@jumper javis]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Aug 11 10:46:50 2006

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL> startup mount;
ORACLE instance started.

Total System Global Area  139531744 bytes
Fixed Size                   452064 bytes
Variable Size             121634816 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> alter session set events 'immediate trace name file_hdrs level 10';

Session altered.

SQL> !

我们看控制文件的信息(选择一个文件):

DATA FILE #4:
(name #4) /opt/oracle/oradata/javis/javis01.dbf
creation size=0 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 4, index=4 krfil=4 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:61 scn: 0x0000.002acb1e 08/11/2006 10:44:38
Stop scn: 0x0000.002acb1e 08/11/2006 10:44:38
Creation Checkpointed at scn:  0x0000.0015078d 06/06/2006 09:41:54

再看数据文件头信息:

FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1407686520=0x53e79778, Db Name='EYGLE'
Activation ID=0=0x0
Control Seq=989=0x3dd, File size=1280=0x500
File Number=4, Blksiz=8192, File Type=3 DATA
Tablespace #4 - EYGLE  rel_fn:4
Creation   at   scn: 0x0000.0015078d 06/06/2006 09:41:54
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x232bee1f scn: 0x0000.0007c781 recovered at 08/11/2006 10:11:26
status:0x0 root dba:0x00000000 chkpt cnt: 64 ctl cnt:63
begin-hot-backup file size: 0
Checkpointed at scn:  0x0000.002acb98 08/11/2006 10:46:24

我们注意到数据文件的chkpt cnt: 64 要大约控制文件的Checkpoint cnt:61,也就是说控制文件是旧的。

此时尝试打开数据库就会出现如下错误:

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Aug 11 10:51:20 2006

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/opt/oracle/oradata/javis/system01.dbf'
ORA-01207: file is more recent than controlfile - old controlfile

Oracle告诉我们,控制文件是旧的。

此时我们可以通过重建控制文件或者从旧的数据备份开始恢复。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: