暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

15_解析Oracle os header结构(1)

数据库技术笔记 2021-02-04
740

1. OS block in an Oracle file

OS Block Header 位于第一个数据文件块中。Oracle使用它来存储操作系统信息。
它是数据文件block 0。不是Oracle 数据文件Block 1中的数据文件头。
block 0的损坏不会对数据造成损害,并且在低于11g的版本中,dbverify/rman不会检测到损坏。在11g中增强了Dbverify来检测它。
dbfsize 可以用来检查Block 0的一致性。
当这个块被损坏时,数据库有时可以被打开并没有异常错误,因为block 0只被一些特定的数据库操作检查,如'CREATE CONTROLFILE'或11g数据库打开期间。 --from mos   [ID 360032.1]


2. 使用bbed检查块结构

[oracle@sourcedb bbed]$ ./l_bbed.sh

BBED: Release 2.0.0.0.0 - Limited Production on Wed Feb 12 21:15:30 2020

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> set file 5 block 0
FILE# 5
BLOCK# 0

BBED> map v
File: oradata/epmsn/hsql01.dbf (5)
Block: 0 Dba:0x01400000
----------------------------------------------------
BBED-00400: invalid blocktype (00)

BBED>
bbed 不支持检查 datafile block 0结构检查;
复制

3. 二进制解析块结构

dd if=/oradata/epmsn/hsql01.dbf of=/home/oracle/orastar/osHeader.dd bs=8192 count=1
vi -b home/oracle/orastar/osHeader.dd
%!xxd -g 1 --十六进制显示,每1个字节为1个块。

0000000: 00 a2 00 00 00 00 c0 ff 00 00 00 00 00 00 00 00 ................
0000010: 66 c8 00 00 00 20 00 00 00 32 00 00 7d 7c 7b 7a f.... ...2..}|{z
0000020: a0 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
复制

offset 1~2: a2, fileType:
offset 7~8: ff c0,
offset 17~18: c8 66, chkval_kcbh
offset 21~22: 20 00, blkSize: 8192.
offset 25~26: 32 00, fileSize: 12800
offset 29~32: 7a 7b 7c 7d, magic
offset 33~34: 81 a0,

offset 1~2: a2, fileType:

data files are of type 0xA2
control files are of type 0xC2
redo log files are of type 0x22

dd of redo file:
dd if=/oradata/epmsn/redo01.log bs=512 count=1 | od -x | head -4
0000000 2200 0000 0000 ffc0 0000 0000 0000 0000
0000020 c867 0000 0200 0000 9000 0001 7c7d 7a7b
0000040 81a0 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000

dd of control file:
dd if=/oradata/epmsn/control01.ctl bs=16384 count=1 | od -x | head -4
0000000 c200 0000 0000 ffc0 0000 0000 0000 0000
0000020 f8a2 0000 4000 0000 02c4 0000 7c7d 7a7b
0000040 81a0 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
复制

offset 7~8: ff c0,
offset 17~18: c8 66, chkval_kcbh

The checksum is the XOR of all the other 2-byte pairs in the block. Thus when a block with a checksum is checked, the XOR of all the 2-byte words in the block should be 0.
以2个byte为一组,除offset16,17(从offset 0开始算起)外对块中所有内容做异或运算XOR(异或运算:如果a、b两个值不相同,则异或结果为1。如果a、b两个值相同,异或结果为0),然后把这个数值写入offset16,17(从offset 0开始算起)。这样整个块的异或计算之后的值就等于0。

图1 chkval of osHeader

offset 21~22: 20 00, blkSize: 8192.
offset 25~26: 32 00, fileSize: 12800

[oracle@sourcedb ~]$ ls -ltr oradata/epmsn/hsql01.dbf
-rw-r----- 1 oracle oinstall 104865792 Feb 12 20:07 oradata/epmsn/hsql01.dbf
[oracle@sourcedb ~]$ echo `expr 104865792 8192`
12801
[oracle@sourcedb ~]$
复制

offset 29~32: 7a 7b 7c 7d, magic

The “magic” is just a file marker and is used by Oracle as means to quickly check if the file is indeed an Oracle file.

offset 33~34: 81 a0

4. 参考文档

How to detect and fix a corruption in the datafile OS header/Block Zero - ORA-27047 [ID 360032.1]


五、说



1、以上内容为个人多次测试结果,由于个人原因,如有分析不足之处还请见谅及指正。

2、文章涉及内容,请勿生产环境模拟。

 


纸上得来终觉浅,绝知此事要躬行。--陆游



感谢您的阅读,如果您觉得有所收获,也欢迎把文章分享给您的朋友。




文章转载自数据库技术笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论