详解段头block和位图block每个offset的含义(非完整版)
本站文章除注明转载外,均为本站原创: 转载自love wife love life —Roger的Oracle/MySQL/PostgreSQL数据恢复博客
前几天跟lunar讨论问题,他提到关于数据库中段头block损坏的恢复以及假如出现位图block损坏等的情况恢复,
如何在没有备份的情况下,那就是个灾难,如果表小还好办,我们可以通过基于rowid等方式去扫描把数据抽取cats
出来,或者你可以使用odu/dul等数据抽取工具。 就像lunar提到的曾经遇到的一个case是有个表的段头坏了,但是
该表非常巨大,超过300g,在这种情况下,如果没有备份,处理起来就非常的麻烦了,虽然这样的情况很少见,但
我这里还是根据她的要求来研究下段头和位图block的结构,以便于我们在极端情况下用bbed等工具去直接修复.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
SQL> conn roger/roger Connected. SQL> select count(1) from t1; COUNT(1) ---------- 51042 SQL> col segment_name for a20 SQL> set lines 120 SQL> l 1 select owner,SEGMENT_NAME,HEADER_FILE,HEADER_BLOCK,blocks from dba_Segments 2* where owner='ROGER' and segment_name='T1' SQL> / OWNER SEGMENT_NAME HEADER_FILE HEADER_BLOCK BLOCKS ------------------------------ -------------------- ----------- ------------ ---------- ROGER T1 2 35 768 SQL> select name from v$datafile where file#=2; NAME ------------------------------------------------------------------- /home/ora10g/oradata/recover/roger01.dbf BBED> info File# Name Size(blks) ----- ---- ---------- 1 /home/ora10g/oradata/recover/system01.dbf 0 2 /home/ora10g/oradata/recover/roger01.dbf 0 3 /home/ora10g/oradata/recover/sysaux01.dbf 0 4 /home/ora10g/oradata/recover/users01.dbf 0 6 /home/ora10g/oradata/recover/undotbs2_01.dbf 0 8 /home/ora10g/oradata/recover/sqlt_01.dbf 0 BBED> set file 2 block 35 FILE# 2 BLOCK# 35 BBED> map /v File: /home/ora10g/oradata/recover/roger01.dbf (2) Block: 35 Dba:0x00800023 ------------------------------------------------------------ BBED-00400: invalid blocktype (35) |
该段头的dump信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
*** SESSION ID:(139.14) 2013-02-25 00:50:49.703 Start dump data blocks tsn: 6 file#: 2 minblk 35 maxblk 35 buffer tsn: 6 rdba: 0x00800023 (2/35) scn: 0x0000.005e08f2 seq: 0x01 flg: 0x04 tail: 0x08f22301 frmt: 0x02 chkval: 0x4715 type: 0x23=PAGETABLE SEGMENT HEADER Hex dump of block: st=0, typ_found=1 D0D9800 0000A223 00800023 005E08F2 04010000 [#...#.....^.....] D0D9810 00004715 00000000 00000000 00000000 [.G..............] D0D9820 00000000 00000015 00000300 00000A9C [................] D0D9830 00000014 00000051 00000080 0080065A [....Q.......Z...] D0D9840 00000000 00000014 00000000 000002D1 [................] D0D9850 00000000 00000000 00000000 00000014 [................] D0D9860 00000051 00000080 0080065A 00000000 [Q.......Z.......] D0D9870 00000014 00000000 000002D1 0080060A [................] D0D9880 0080060A 00000000 00000000 00000000 [................] D0D9890 00000000 00000000 00000000 00000000 [................] Repeat 3 times D0D98D0 00000001 00002000 00000000 00001434 [..... ......4...] D0D98E0 00000000 00800022 00000001 0080060A [...."...........] D0D98F0 00800022 00000000 00000000 00000000 ["...............] D0D9900 00000000 00000000 00000015 00000000 [................] D0D9910 0000E846 10000000 00800021 00000008 [F.......!.......] D0D9920 00800029 00000008 00800031 00000008 [).......1.......] D0D9930 00800039 00000008 00800041 00000008 [9.......A.......] D0D9940 00800049 00000008 00800051 00000008 [I.......Q.......] D0D9950 00800059 00000008 00800061 00000008 [Y.......a.......] D0D9960 00800069 00000008 00800071 00000008 [i.......q.......] D0D9970 00800079 00000008 00800081 00000008 [y...............] D0D9980 00800501 00000008 00800309 00000008 [................] D0D9990 00800311 00000008 00800389 00000080 [................] D0D99A0 00800409 00000080 00800509 00000080 [................] D0D99B0 00800589 00000080 00800609 00000080 [................] D0D99C0 00000000 00000000 00000000 00000000 [................] Repeat 142 times D0DA2B0 00800021 00800024 00800021 00800029 [!...$...!...)...] D0DA2C0 00800031 00800032 00800031 00800039 [1...2...1...9...] D0DA2D0 00800041 00800042 00800041 00800049 [A...B...A...I...] D0DA2E0 00800051 00800052 00800051 00800059 [Q...R...Q...Y...] D0DA2F0 00800061 00800062 00800061 00800069 [a...b...a...i...] D0DA300 00800071 00800072 00800071 00800079 [q...r...q...y...] D0DA310 00800081 00800082 00800081 00800501 [................] D0DA320 00800309 0080030A 00800309 00800311 [................] D0DA330 00800389 0080038B 00800409 0080040B [................] D0DA340 00800509 0080050B 00800589 0080058B [................] D0DA350 00800609 0080060B 00000000 00000000 [................] D0DA360 00000000 00000000 00000000 00000000 [................] Repeat 141 times D0DAC40 00000000 00000000 00800022 00000000 [........".......] D0DAC50 00000000 00000000 00000000 00000000 [................] Repeat 185 times D0DB7F0 00000000 00000000 00000000 08F22301 [.............#..] Extent Control Header ----------------------------------------------------------------- Extent Header:: spare1: 0 spare2: 0 #extents: 21 #blocks: 768 last map 0x00000000 #maps: 0 offset: 2716 Highwater:: 0x0080065a ext#: 20 blk#: 81 ext size: 128 #blocks in seg. hdr's freelists: 0 #blocks below: 721 mapblk 0x00000000 offset: 20 Unlocked -------------------------------------------------------- Low HighWater Mark : Highwater:: 0x0080065a ext#: 20 blk#: 81 ext size: 128 #blocks in seg. hdr's freelists: 0 #blocks below: 721 mapblk 0x00000000 offset: 20 Level 1 BMB for High HWM block: 0x0080060a Level 1 BMB for Low HWM block: 0x0080060a -------------------------------------------------------- Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0 L2 Array start offset: 0x00001434 First Level 3 BMB: 0x00000000 L2 Hint for inserts: 0x00800022 Last Level 1 BMB: 0x0080060a ---一级位图block dba Last Level II BMB: 0x00800022 ---二级位图block dba Last Level III BMB: 0x00000000 Map Header:: next 0x00000000 #extents: 21 obj#: 59462 flag: 0x10000000 Inc # 0 Extent Map ----------------------------------------------------------------- 0x00800021 length: 8 0x00800029 length: 8 0x00800031 length: 8 0x00800039 length: 8 0x00800041 length: 8 0x00800049 length: 8 0x00800051 length: 8 0x00800059 length: 8 0x00800061 length: 8 0x00800069 length: 8 0x00800071 length: 8 0x00800079 length: 8 0x00800081 length: 8 0x00800501 length: 8 0x00800309 length: 8 0x00800311 length: 8 0x00800389 length: 128 0x00800409 length: 128 0x00800509 length: 128 0x00800589 length: 128 0x00800609 length: 128 从这个extent map信息,可以得知该segment的大小为768个block. Auxillary Map -------------------------------------------------------- Extent 0 : L1 dba: 0x00800021 Data dba: 0x00800024 这里是位图block的map 列表,换句话讲,这里的block 也都是一级位图block。 Extent 1 : L1 dba: 0x00800021 Data dba: 0x00800029 第1个位图block 0x00800021对应的data block范围是:21~29 Extent 2 : L1 dba: 0x00800031 Data dba: 0x00800032 Extent 3 : L1 dba: 0x00800031 Data dba: 0x00800039 第2个位图block 0x00800031 对应的data block范围是:32~39 Extent 4 : L1 dba: 0x00800041 Data dba: 0x00800042 上面的length就是其extent的block个数. Extent 5 : L1 dba: 0x00800041 Data dba: 0x00800049 Extent 6 : L1 dba: 0x00800051 Data dba: 0x00800052 Extent 7 : L1 dba: 0x00800051 Data dba: 0x00800059 Extent 8 : L1 dba: 0x00800061 Data dba: 0x00800062 Extent 9 : L1 dba: 0x00800061 Data dba: 0x00800069 Extent 10 : L1 dba: 0x00800071 Data dba: 0x00800072 Extent 11 : L1 dba: 0x00800071 Data dba: 0x00800079 Extent 12 : L1 dba: 0x00800081 Data dba: 0x00800082 Extent 13 : L1 dba: 0x00800081 Data dba: 0x00800501 Extent 14 : L1 dba: 0x00800309 Data dba: 0x0080030a Extent 15 : L1 dba: 0x00800309 Data dba: 0x00800311 Extent 16 : L1 dba: 0x00800389 Data dba: 0x0080038b Extent 17 : L1 dba: 0x00800409 Data dba: 0x0080040b Extent 18 : L1 dba: 0x00800509 Data dba: 0x0080050b Extent 19 : L1 dba: 0x00800589 Data dba: 0x0080058b Extent 20 : L1 dba: 0x00800609 Data dba: 0x0080060b -------------------------------------------------------- Second Level Bitmap block DBAs -------------------------------------------------------- DBA 1: 0x00800022 End dump data blocks tsn: 6 file#: 2 minblk 35 maxblk 35 |
从上面我们可以看到,对于段头,里面的信息其实很简单,我们可以使用dbms包去转换dba地址为file、block号,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SQL> select dbms_utility.data_block_address_file(TO_NUMBER('80060a', 'XXXXXXXX')) file_id, dbms_utility.data_block_address_block(TO_NUMBER('80060a', 'XXXXXXXX')) block_id from dual; 2 FILE_ID BLOCK_ID ---------- ---------- 2 1546 SQL> select dbms_utility.data_block_address_file(TO_NUMBER('800022', 'XXXXXXXX')) file_id, 2 dbms_utility.data_block_address_block(TO_NUMBER('800022', 'XXXXXXXX')) block_id from dual; FILE_ID BLOCK_ID ---------- ---------- 2 34 SQL> |
如下是针对段头block的dump信息:
++++++++alter system dump datafile 2 block 35
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
D0D9800 0000A223 00800023 005E08F2 04010000 [#...#.....^.....] D0D9810 00004715 00000000 00000000 00000000 [.G..............] D0D9820 00000000 00000015 00000300 00000A9C [................] D0D9830 00000014 00000051 00000080 0080065A [....Q.......Z...] D0D9840 00000000 00000014 00000000 000002D1 [................] D0D9850 00000000 00000000 00000000 00000014 [................] D0D9860 00000051 00000080 0080065A 00000000 [Q.......Z.......] D0D9870 00000014 00000000 000002D1 0080060A [................] D0D9880 0080060A 00000000 00000000 00000000 [................] D0D9890 00000000 00000000 00000000 00000000 [................] Repeat 3 times D0D98D0 00000001 00002000 00000000 00001434 [..... ......4...] D0D98E0 00000000 00800022 00000001 0080060A [...."...........] D0D98F0 00800022 00000000 00000000 00000000 ["...............] D0D9900 00000000 00000000 00000015 00000000 [................] D0D9910 0000E846 10000000 00800021 00000008 [F.......!.......] D0D9920 00800029 00000008 00800031 00000008 [).......1.......] D0D9930 00800039 00000008 00800041 00000008 [9.......A.......] D0D9940 00800049 00000008 00800051 00000008 [I.......Q.......] D0D9950 00800059 00000008 00800061 00000008 [Y.......a.......] D0D9960 00800069 00000008 00800071 00000008 [i.......q.......] D0D9970 00800079 00000008 00800081 00000008 [y...............] D0D9980 00800501 00000008 00800309 00000008 [................] D0D9990 00800311 00000008 00800389 00000080 [................] D0D99A0 00800409 00000080 00800509 00000080 [................] D0D99B0 00800589 00000080 00800609 00000080 [................] D0D99C0 00000000 00000000 00000000 00000000 [................] Repeat 142 times D0DA2B0 00800021 00800024 00800021 00800029 [!...$...!...)...] D0DA2C0 00800031 00800032 00800031 00800039 [1...2...1...9...] D0DA2D0 00800041 00800042 00800041 00800049 [A...B...A...I...] D0DA2E0 00800051 00800052 00800051 00800059 [Q...R...Q...Y...] D0DA2F0 00800061 00800062 00800061 00800069 [a...b...a...i...] D0DA300 00800071 00800072 00800071 00800079 [q...r...q...y...] D0DA310 00800081 00800082 00800081 00800501 [................] D0DA320 00800309 0080030A 00800309 00800311 [................] D0DA330 00800389 0080038B 00800409 0080040B [................] D0DA340 00800509 0080050B 00800589 0080058B [................] D0DA350 00800609 0080060B 00000000 00000000 [................] D0DA360 00000000 00000000 00000000 00000000 [................] Repeat 141 times D0DAC40 00000000 00000000 00800022 00000000 [........".......] D0DAC50 00000000 00000000 00000000 00000000 [................] Repeat 185 times D0DB7F0 00000000 00000000 00000000 08F22301 [.............#..] ---bbed dump file 2 block 35 BBED> d /v count 512 File: /home/ora10g/oradata/recover/roger01.dbf (2) Block: 35 Offsets: 0 to 511 Dba:0x00800023 ------------------------------------------------------- 23a20000 23008000 f2085e00 00000104 l #.#...^..... 15470000 00000000 00000000 00000000 l .G.............. 00000000 15000000 00030000 9c0a0000 l ................ 14000000 51000000 80000000 5a068000 l ....Q.......Z... 00000000 14000000 00000000 d1020000 l .............. 00000000 00000000 00000000 14000000 l ................ 51000000 80000000 5a068000 00000000 l Q.......Z....... 14000000 00000000 d1020000 0a068000 l .............. 0a068000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 01000000 00200000 00000000 34140000 l ..... ......4... 00000000 22008000 01000000 0a068000 l ...."........... 22008000 00000000 00000000 00000000 l "............... 00000000 00000000 15000000 00000000 l ................ 46e80000 00000010 21008000 08000000 l F.....!....... 29008000 08000000 31008000 08000000 l ).......1....... 39008000 08000000 41008000 08000000 l 9.......A....... 49008000 08000000 51008000 08000000 l I.......Q....... 59008000 08000000 61008000 08000000 l Y.......a....... 69008000 08000000 71008000 08000000 l i.......q....... 79008000 08000000 81008000 08000000 l y............... 01058000 08000000 09038000 08000000 l ................ 11038000 08000000 89038000 80000000 l ................ 09048000 80000000 09058000 80000000 l ................ 89058000 80000000 09068000 80000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ |
如下是段头block的每个offset的含义,这里我只是列举了大部分相对重要的offset:
offset 1: 23 表示block type 类型,23表示表段头,0x0b表示datafile header block类型.
offset 2: a2 表示block格式类型,这个跟普通的block格式类型一样。
offset 5~8: 23008000 表示该block的rdba地址,可以进行手工进行转换。
offset 9~14: f2085e00.0000 表示该block的scn值.
offset 15: 01 表示sequences号,是用于计算tail值用的.
offset 16: 04 表示flag值,针对block的flag值有如下几种属性:
#define KCBHFNEW 0x01 /* new block – zeroed data area */
#define KCBHFDLC 0x02 /* Delayed Logging Change advanced SCN/seq */
#define KCBHFCKV 0x04 /* ChecK Value saved – block xor’s to zero */
#define KCBHFTMP 0x08 /* Temporary block */
offset 17~18: 1547 表示block的check值,该值无所谓,如果用bbed进行修改后,可以sum apply会重新校验生成。
offset 37: 15 表示该段头信息所包含的extent个数,转换为10进制为21,即包含21个extent。
offset 41~42:0003,由于我这里字节序是32位,bbed看到的信息是反的,所以应该是0300,转换后为768,表示
这个段所包含的block个数,即段的大小,单位block
offset 45~46: 9c0a 表示extent header所在的offset,转换为10进制后为2716.
offset 49: 14 表示高水位标记的extent号.
offset 53:51 对于段头dump的blk#值,应该是值的block号
offset 57: 80 表示该extent所包含的block个数。 (offset 49~57 对应的都的高水位标记)
offset 60~64: 5a068000 表示表水位标记的rdba地址.
offset 69: 14 表示mapblk 对于的offset,居然含义不太清楚。
offset 76~80:d1020000 表示高水位标记下的blocks总数.
offset 92: 14 表示低水位标记的extent号.
offset 104~108: 5a068000 表示低水位标记的rdba地址.
offset 120~124: 5a068000 表示一级位图block的High HWM block rdba地址
offset 125~128: 5a068000 表示一级位图block的Low HWM block rdba地址
offset 213~214:2000 表示block size大小.
offset 221~224: 34140000 表示L2 Array start offset.
offset 229~232: 22008000 表示二级位图L2 Hint for inserts rdba地址.
offset 336~240: 0a068000 表示Last Level 1 BMB rdba地址。
offset 241~244:22008000 表示Last Level II BMB rdba地址.
offset 257~258: 46e8 表示object id号.
offset 261~264: 00000010 表示map header 的flag地址,段头的dump都是这个值.
offset 8189~8192:08F22301 表示该block的tail值。 该值属性为SCN bas+type+scn seq
中间还有一些Extent Map和Auxillary Map 信息,不多说了。
我想,了解上述的段头block的信息后,出现段头坏的情况,用bbed足以修复了。
接下来我们来看下位图block的结构,这里先说一级位图block.如下是一级位图block的dump信息:
+++++++ alter system dump datafile 2 block 1546
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
Start dump data blocks tsn: 6 file#: 2 minblk 1546 maxblk 1546 buffer tsn: 6 rdba: 0x0080060a (2/1546) scn: 0x0000.005e08f0 seq: 0x02 flg: 0x04 tail: 0x08f02002 frmt: 0x02 chkval: 0x6a39 type: 0x20=FIRST LEVEL BITMAP BLOCK Hex dump of block: st=0, typ_found=1 Dump of memory from 0x0D0D9800 to 0x0D0DB800 D0D9800 0000A220 0080060A 005E08F0 04020000 [ .........^.....] D0D9810 00006A39 00000000 00000000 00000000 [9j..............] D0D9820 00000000 00000000 00000000 00000000 [................] Repeat 1 times D0D9840 00000000 00000000 00000000 00000004 [................] D0D9850 FFFFFFFF 0000002F 00000000 00000040 [..../.......@...] D0D9860 00010001 00000000 00000000 00000000 [................] D0D9870 00000000 00000011 00000000 00000000 [................] D0D9880 00000000 00000000 00000000 00000000 [................] D0D9890 00800022 00000011 00000014 00000051 ["...........Q...] D0D98A0 00000080 0080065A 00000000 00000014 [....Z...........] D0D98B0 00000000 000002D1 00000000 00000001 [................] D0D98C0 0000E846 00000000 00000000 00800649 [F...........I...] D0D98D0 00000040 00000000 00000000 00000000 [@...............] D0D98E0 00000000 00000000 00000000 00000000 [................] Repeat 9 times D0D9980 00000000 00000000 00000000 11111111 [................] D0D9990 11111111 00000010 00000000 00000000 [................] D0D99A0 00000000 00000000 00000000 00000000 [................] Repeat 484 times D0DB7F0 00000000 00000000 00000000 08F02002 [............. ..] Dump of First Level Bitmap Block -------------------------------- nbits : 4 nranges: 1 parent dba: 0x00800022 poffset: 17 unformatted: 47 total: 64 first useful block: 0 owning instance : 1 instance ownership changed at Last successful Search Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0 Extent Map Block Offset: 4294967295 First free datablock : 17 Bitmap block lock opcode 0 Locker xid: : 0x0000.000.00000000 Inc #: 0 Objd: 59462 HWM Flag: HWM Set Highwater:: 0x0080065a ext#: 20 blk#: 81 ext size: 128 #blocks in seg. hdr's freelists: 0 #blocks below: 721 mapblk 0x00000000 offset: 20 -------------------------------------------------------- DBA Ranges : -------------------------------------------------------- 0x00800649 Length: 64 Offset: 0 0:FULL 1:FULL 2:FULL 3:FULL 4:FULL 5:FULL 6:FULL 7:FULL 8:FULL 9:FULL 10:FULL 11:FULL 12:FULL 13:FULL 14:FULL 15:FULL 16:FULL 17:unformatted 18:unformatted 19:unformatted 20:unformatted 21:unformatted 22:unformatted 23:unformatted 24:unformatted 25:unformatted 26:unformatted 27:unformatted 28:unformatted 29:unformatted 30:unformatted 31:unformatted 32:unformatted 33:unformatted 34:unformatted 35:unformatted 36:unformatted 37:unformatted 38:unformatted 39:unformatted 40:unformatted 41:unformatted 42:unformatted 43:unformatted 44:unformatted 45:unformatted 46:unformatted 47:unformatted 48:unformatted 49:unformatted 50:unformatted 51:unformatted 52:unformatted 53:unformatted 54:unformatted 55:unformatted 56:unformatted 57:unformatted 58:unformatted 59:unformatted 60:unformatted 61:unformatted 62:unformatted 63:unformatted -------------------------------------------------------- End dump data blocks tsn: 6 file#: 2 minblk 1546 maxblk 1546 ----bbed dump BBED> set file 2 block 1546 FILE# 2 BLOCK# 1546 BBED> d /v count 512 File: /home/ora10g/oradata/recover/roger01.dbf (2) Block: 1546 Offsets: 0 to 511 Dba:0x0080060a ------------------------------------------------------- 20a20000 0a068000 f0085e00 00000204 l .....^..... 396a0000 00000000 00000000 00000000 l 9j.............. 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 04000000 l ................ ffffffff 2f000000 00000000 40000000 l ..../.......@... 01000100 00000000 00000000 00000000 l ................ 00000000 11000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 22008000 11000000 14000000 51000000 l "...........Q... 80000000 5a068000 00000000 14000000 l ....Z........... 00000000 d1020000 00000000 01000000 l .............. 46e80000 00000000 00000000 49068000 l F.........I... 40000000 00000000 00000000 00000000 l @............... 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 11111111 l ................ 11111111 10000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 00000000 00000000 00000000 l ................ 00000000 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: 20 表示block type类型,20表示一级位图block,21表示二级位图block,22表示三级位图block。
offset 2:a2 表示block格式类型,这个跟普通的block格式类型一样
offset 5~8: 0a068000 表示该block的rdba地址.
offset 9~12: f0085e00 表示scn值.
offset 15: 02 表示sequence值
offset 16: 04 表示flag值.
offset 17~20: 396a0000 表示block 的check 值.
offset 81~84: ffffffff 表示Extent Map Block Offset值,这里该位图block没有extent map,所以默认为最大值也就是8个f.
offset 85: 2f 表示unformatted block的个数. 即高水位上的block个数。
offset 92: 40 表示该位图block所对应的data block个数.
offset 117: 11 表示该位图block所对应的parent dba的offset值.
offset 145~148: 22008000 表示该位图block的parent block dba地址。
offset 165~168:5a068000 表示Highwater 标记dba地址.
offset 181~184: d1020000 表示高水位标记下的block总数.
offset 193~196: 46e80000 表示object id号.
offset 205~208:49068000 表示该位图block所对应的数据块dba ranges地址的起始值。
最后我们来看下二级位图block的结构:
Start dump data blocks tsn: 6 file#: 2 minblk 34 maxblk 34
buffer tsn: 6 rdba: 0x00800022 (2/34)
scn: 0x0000.0061c551 seq: 0x03 flg: 0x04 tail: 0xc5512103
frmt: 0x02 chkval: 0x6c9d type: 0x21=SECOND LEVEL BITMAP BLOCK
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x0D0D9800 to 0x0D0DB800
D0D9800 0000A221 00800022 0061C551 04030000 [!…”…Q.a…..]
D0D9810 00006C9D 00000000 00000000 00000000 [.l…………..]
D0D9820 00000000 00000000 00000000 00000000 […………….]
Repeat 1 times
D0D9840 00000000 00000000 00000000 00800023 […………#…]
D0D9850 00000064 00000001 00000062 00000000 [d…….b…….]
D0D9860 00000000 00000000 0000E846 00000001 [……..F…….]
D0D9870 00000000 00800021 00010001 00800031 [….!…….1…]
……..
D0D9B90 00010001 00000000 00000000 00000000 […………….]
D0D9BA0 00000000 00000000 00000000 00000000 […………….]
Repeat 452 times
D0DB7F0 00000000 00000000 00000000 C5512103 [………….!Q.]
Dump of Second Level Bitmap Block
number: 100 nfree: 1 ffree: 98 pdba: 0x00800023
Inc #: 0 Objd: 59462
opcode:0
xid:
L1 Ranges :
——————————————————–
0x00800021 Free: 1 Inst: 1
0x00800031 Free: 1 Inst: 1
0x00800041 Free: 1 Inst: 1
0x00800051 Free: 1 Inst: 1
………
可以看到,二级位图block的结构也不复杂,除了头部的信息跟前面的一级位图block基本上一致外,后面就是一个
对应的一级位图block的dba 范围列表。所以这里我就不再相信去描述二级位图block的每个offset的具体含义了。
同理,三级位图block的结构也是类似的,不同的是除开前面的头部信息外,后面跟着的是对应的二级位图block的范围列表信息。
事实上,对于8k的block size,要出现三级位图block是非常困难的,一般情况下大家根本遇不到的。
最后简单总结下:
1. 针对段头损坏的情况,如果有备份,可以使用rman的blockrecover,如果没有备份,那么就很悲剧了。
2. 如果位图block损坏,即使没有备份,也可以使用基于rowid的方式进行cats抽取数据。
3. 针对上面的2种情况,都可以使用odu、dul等工具抽取数据。
4. 如果问题不复杂的话,在备份数据文件后,你可以使用bbed去修复上面的块损坏,不过这个要慎重。
5. 我这里是32位,bbed dump是反的,另外我是从offset 1开始(图方便计算),大家自己算的时候减1个offset即可.
6. 本来不计划发出来的,想想还是发出来,免得大家说我藏着掖着,但是注意,出问题了,我概不负责哦!!!
最后是贴个模拟段头损坏的情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Mon Feb 25 07:00:24 PST 2013 Hex dump of (file 2, block 35) in trace file /home/ora10g/admin/recover/bdump/recover_j000_5559.trc Corrupt block relative dba: 0x00800023 (file 2, block 35) Bad header found during buffer read Data in bad block: type: 85 format: 5 rdba: 0x00888823 last change scn: 0x0000.0061c639 seq: 0x1 flg: 0x04 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xc6392301 check value in block header: 0x8778 computed block checksum: 0xab89 Reread of rdba: 0x00800023 (file 2, block 35) found same corrupted data Mon Feb 25 07:00:24 PST 2013 Corrupt Block Found TSN = 6, TSNAME = ROGER RFN = 2, BLK = 35, RDBA = 8388643 OBJN = 59462, OBJD = 59462, OBJECT = T1, SUBOBJECT = SEGMENT OWNER = ROGER, SEGMENT TYPE = Table Segment Mon Feb 25 07:00:24 PST 2013 |
使用使用bbed修改block前面的部分即可,dba地址我们可以转换进行反推,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SQL> select dbms_utility.data_block_address_file(TO_NUMBER('800023', 'XXXXXXXX')) file_id, dbms_utility.data_block_address_block(TO_NUMBER('800023', 'XXXXXXXX')) block_id from dual; 2 FILE_ID BLOCK_ID ---------- ---------- 2 35 SQL> SQL> select count(1) from roger.t1; COUNT(1) ---------- 432330 |
5 Responses to “详解段头block和位图block每个offset的含义(非完整版)”
[…] 详见原文博客链接第:详解段头block和位图block每个offset的… 作者:lovewifelovelife 发表于2013-2-28 20:46:55 原文链接 阅读:25 评论:0 查看评论 […]
顶roger,加油,精辟而独到.学习
请教一下,基于rowid等方式去扫描把数据抽取cats
出来 ,是怎么做的。
找出是哪个块损坏了,这个块rowid排除出去:例如这个块有rowid10、rowid11、rowid12,可以create table t1 as select * from tab where rowidrowid12;
这样来做!
奇怪了 打空格 怎么变成=“”了!
Leave a Reply
You must be logged in to post a comment.