最近在研究块的内部结构,把文档简单整理了一下,和大家分享一下。该篇文章借助dump和BBED对数据
库内部结构进行了分析,最后附加了一个用BBED解决ORA-1200错误的小例子。在总结的过程中参考了
《Disassembling the Oracle Data Block》以及网上的翻译版本。
dump说明
创建表空间和测试表:
create tablespace testblock datafile '/opt/oracle/oradata/oradb/testblock01.dbf' size 100M;
create table testblock(
id number,
name varchar(4)
) tablespace testblock;
插入3条数据然后提交:
SQL> insert into testblock values(1,'a');
SQL> insert into testblock values(2,'b');
SQL> insert into testblock values(3,'c');
SQL> commit;
SQL> select * from testblock;
ID NAME
---------- --------
1 a
2 b
3 c
SQL> select rowid,dbms_rowid.rowid_relative_fno(rowid) rel_fno,dbms_rowid.rowid_block_number(rowid)
blockno from testblock;
ROWID REL_FNO BLOCKNO
------------------ ---------- ----------
AAANK4AAFAAAAAQAAA 5 16
AAANK4AAFAAAAAQAAB 5 16
AAANK4AAFAAAAAQAAC 5 16
我们看到这3行数据都在5号数据文件的第16个块
执行数据块dump:
SQL> alter system dump datafile 5 block 16;
以下是该数据块的完整dump结果:
Start dump data blocks tsn: 7 file#: 5 minblk 16 maxblk 16
buffer tsn: 7 rdba: 0x01400010 (5/16)
scn: 0x0000.001732d3 seq: 0x01 flg: 0x04 tail: 0x32d30601
frmt: 0x02 chkval: 0x84cb type: 0x06=trans data
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x0CEB6400 to 0x0CEB8400
CEB6400 0000A206 01400010 001732D3 04010000 [......@..2......]
CEB6410 000084CB 00000001 0000D2B8 001732D3 [.............2..]
CEB6420 00000000 00320002 01400009 00200006 [......2...@... .]
CEB6430 00000271 00800205 00130257 00008000 [q.......W.......]
CEB6440 001732C4 00060008 00000279 00800351 [.2......y...Q...]
CEB6450 00150278 00000001 00000000 00000000 [x...............]
CEB6460 00000000 00030100 0018FFFF 1F651F5E [............^.e.]
CEB6470 00001F65 1F5E0003 1F801F66 00000000 [e.....^.f.......]
CEB6480 00000000 00000000 00000000 00000000 [................]
Repeat 499 times
CEB83C0 022C0000 02C10202 002C6101 03C10202 [..,......a,.....]
CEB83D0 012C6201 03C10202 2C626202 C1020200 [.b,......bb,....]
CEB83E0 61610202 0202002C 630104C1 0202002C [..aa,......c,...]
CEB83F0 620103C1 0202002C 610102C1 32D30601 [...b,......a...2]
Block header dump: 0x01400010
Object id on Block? Y
seg/obj: 0xd2b8 csc: 0x00.1732d3 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x1400009 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0006.020.00000271 0x00800205.0257.13 C--- 0 scn 0x0000.001732c4
0x02 0x0008.006.00000279 0x00800351.0278.15 ---- 1 fsc 0x0000.00000000
data_block_dump,data header at 0xceb6464
===============
tsiz: 0x1f98
hsiz: 0x18
pbl: 0x0ceb6464
bdba: