免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2431 | 回复: 0
打印 上一主题 下一主题

不完全详解 os block header [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-05 17:44 |只看该作者 |倒序浏览
原帖地址 http://www.killdb.com/?p=390
什么是os block header?它有哪些作用?如果它损害了怎么办?

下面是关于os block header的解释,来自MOS。
The OS Block Header is in the first datafile block. It is used by Oracle
to store Operating System information.

It is the Block Zero. It is not the datafile header which is in Oracle Block 1.
Corruption in Block Zero will not cause damage to the data and it is not detected
by dbverify/rman. When this block is corrupted the database may be opened with no
errors. This block contains a magic number to identify the platform, the size of
the datafile in

我这里使用bbed来进行分析,当然你也可以使用UE或dd等命令来进行操作。
BBED> info
File#  Name                                                        Size(blks)
-----  ----                                                        ----------
     1  /oracle/product/oradata/roger/system01.dbf                       61440
     2  /oracle/product/oradata/roger/undotbs01.dbf                     137600
     3  /oracle/product/oradata/roger/sysaux01.dbf                       32000
     4  /oracle/product/oradata/roger/users01.dbf                        12800
     5  /oracle/product/oradata/roger/roger1.dbf                          2560

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

BBED> map /v
File: /oracle/product/oradata/roger/roger1.dbf (5)
Block: 0                                     Dba:0x01400000
------------------------------------------------------------
BBED-00400: invalid blocktype (00)


BBED> d /v
File: /oracle/product/oradata/roger/roger1.dbf (5)
Block: 0       Offsets:    0 to  511  Dba:0x01400000
-------------------------------------------------------
00a20000 0000c0ff 00000000 00000000 l .?...?........
66f00000 00200000 000a0000 7d7c7b7a l f?.. ......}|{z
a0810000 00000000 00000000 00000000 l ?..............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
........
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>

我们可以看到大部分地方是没信息的,只有几个地方,分别是如下:

offset 1~2   00a2
offset 7~8   c0ff
offset 17~18 66f0
offset 22~23 2000
offset 26~27 0a00
offset 29~32 7d7c7b7a
offset 33~34 a081


offset 22~23 的两个byte,这里对应的是block大小,如下:
SQL> select to_number(2000,'XXXX') from dual;

TO_NUMBER(2000,'XXXX')
----------------------
                  8192

offset 26~27 的0a00 是对应的datafile的大小,实际上是block个数,如下:
SQL>  select to_char(2560,'xxx') from dual;

TO_C
----
a00

SQL> !
[oracle@roger ~]$ ls -ltr /oracle/product/oradata/roger/roger1.dbf
-rw-r-----  1 oracle dba 20979712 Sep  4 18:09 /oracle/product/oradata/roger/roger1.dbf
[oracle@roger ~]$

20979712/8192 - 1个os block header =2560


offset 29~32 的4个byte是magic number,10g版本所有平台该4个byte值都完全一样。
至于说其他版本比如9i,11gR1,11gR2我还没进行测试。


[oracle@roger ~]$ dbfsize  /oracle/product/oradata/roger/roger1.dbf

Database file: /oracle/product/oradata/roger/roger1.dbf
Database file type: file system
Database file size: 2560 8192 byte blocks
[oracle@roger ~]$


如何才能知道下面这几个的含义呢?

offset 1~2   00a2
offset 7~8   c0ff
offset 17~18 66f0

于是我想到了将该datafile resize后来进行观察,看看发生了什么改变。
SQL> alter database datafile 5 resize 30m;

Database altered.

SQL>
BBED> d /v
File: /oracle/product/oradata/roger/roger1.dbf (5)
Block: 0       Offsets:    0 to  511  Dba:0x01400000
-------------------------------------------------------
00a20000 0000c0ff 00000000 00000000 l .?...?........
66f50000 00200000 000f0000 7d7c7b7a l f?.. ......}|{z
a0810000 00000000 00000000 00000000 l ?..............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
...........
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>

经过一对比,我们可以发现如下规律:

f566  62822
f066  61542  --->62822-61542=1280
SQL> select (blocks -2560) from dba_data_files where file_id=5;

(BLOCKS-2560)
-------------
         1280
         
所以我猜测ffset 17~18 这2个byte应该是跟datafile的增长相关,单位为block。
另外通过前面dbfsize的结果来看,我猜测offset 2的a2代表的应该是datafile类型。

至于其他一些offset的含义,目前我还不知道是什么意思,如果谁知道,记得告诉我。

最后来谈谈跟os block header相关的数据库恢复。
如果os block header出现损坏,你可以会遇到如下错误:
ORA-27047: unable to read the header block of file

出现该错误其实并不要紧,可以通过resize datafile来重新格式化os block header,
关于这点大家可以参考MOS文档,如果是文件系统本身损坏了,那么可能需要用fsck等
os工具去进行磁盘的修改,MOS文档如下:
How to detect and fix a corruption in the datafile OS header/Block Zero - ORA-27047 [ID 360032.1]

最后补充一点,因为的我的虚拟机是linux x86,属于little 平台,所以用bbed dump出来
的字节序是反的,如果觉得这样看着不方便,我们可以借助dd 和od命令来看,如下:
[oracle@roger ~]$ dd if=/oracle/product/oradata/roger/roger1.dbf bs=8192 count=1 | od -x | head -4
1+0 records in
1+0 records out
0000000 a200 0000 0000 ffc0 0000 0000 0000 0000
0000020 f566 0000 2000 0000 0f00 0000 7c7d 7a7b
0000040 81a0 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000

或者
[oracle@roger ~]$ od -x -N 64 /oracle/product/oradata/roger/roger1.dbf
0000000 a200 0000 0000 ffc0 0000 0000 0000 0000
0000020 f566 0000 2000 0000 0f00 0000 7c7d 7a7b
0000040 81a0 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
0000100
[oracle@roger ~]$
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP