Oracle 摘去数据块的面纱
| Offset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
| ? | ||||||||||||||||
| 00018000h | 6 | A2 | 0 | 0 | 0c | 0 | 80 | 3 | 8b | 61 | 15 | 0 | 0 | 0 | 3 | 4 |
| ? | type | frmt | spare1/2 | rdba | bas | wrp | seq | flg | ||||||||
| ? The Cache Header The Cache Header : ? 注:@符號后數字表示塊內偏移字節數??????????????? Struct? kcbh? 20 bytes @0?? :此結構體共20字節,塊內偏移為0字節,即塊首。 ???? ub1 type_kcbh??????? @0?? :1=undo segment header block; 2=undo data block; 5= data segment header block; 6=data block ???? ub1 frmt_kcbh??????? @1?? :應該是用來區分版本。Oracle 8之前值為1,之后為2,我的10g為A2 ???? ub1 spare1_kcbh?? @2?? :未被使用 ???? ub1 spare2_kcbh?? @3?? :未被使用 ???? ub4 rdba_kcbh?????? @4?? :0x0380000c 轉換成2進制后它的前10 bit 表示file id(算法不確定);后22 bit 表示的block id ???? ub4 bas_kcbh??? @8?? :低位字節(SCN base)ub2 wrp_kcbh??? @12? :高位字節(SCN wrap) ???? ub1 seq_kcbh???????? @14? :參照http://www.itpub.net/thread-100750-4-1.html ???? ub1 flg_kcbh?????????? @15 ???? ub2 chkval_kcbh??? @16? :跟db_block_checksum 參數有關系。 ???? ub2 spare3_kcbh?? @18 ? | ||||||||||||||||
| 00018010h | 9d | af | 0 | 0 | 1 | 0 | 0 | 0 | 4 | D0 | 0 | 0 | 6a | 51 | 15 | 0 |
| ? | chkval | Spare3 | typ | ? | sid | csc | ||||||||||
| ? The Transaction Header : ?????????????????? Struct ?ktbbh? 72 bytes?? ??@20?? :共72 bytes,塊內偏移量20 bytes ??? ub1 ktbbhtyp???? @20?? :1byte。1=data; 2=index。后面3字節空置?????????? ??? union ktbbhsid?? @24? :指在OBJ$中記錄的segment的object number?? ??? struct ktbbhcsc?? @28? : 前6字節為SCN at last block cleanout,后2字節用途不清?? ??? b2 ktbbhict????? @36? : ITL 的slot數量?? ??? ub1 ktbbhflg???? @38????? ??? ub1 ktbbhfsl???? @39????? ??? ub4 ktbbhfnx??? @40?? :自由列表中下一塊的地址?? struct ktbbhitl[2] @44? : 2個ITL? 共48字節,塊內偏移44字? ? | ||||||||||||||||
| 00018020h | 0 | 0 | 0 | 0 | 2 | 0 | 32 | 0 | 9 | 0 | 80 | 3 | 3 | 0 | 5 | 0 |
| ? | csc | ktbbhict | flg | fsl | fnx | xid | ||||||||||
| ? 第1個ITL ???? ?xid :? 8bytes。Transaction ID (UndoSeg.Slot.Wrap)(select XIDUSN, XIDSLOT,XIDSQN from v$transaction;) ???? uba :? 8bytes。Undo address (UndoDBA.SeqNo.RecordNo) ? Lck Flag :? 2bytes。 ??Scn/Fsc :? 6bytes。Commit SCN或者快速提交(Fast Commit Fsc)的SCN ? | ||||||||||||||||
| 00018030h | 74 | 2 | 0 | 0 | 43 | 3 | 80 | 0 | A2 | 1 | 29 | 0 | 0 | 80 | 0 | 0 |
| ? | xid | uba | Lck Flag | Scn/Fsc | ||||||||||||
| 00018040h | AE | 10 | 15 | 0 | 2 | 0 | 0C | 0 | 51 | 2 | 0 | 0 | 48 | 0A | 80 | 0 |
| ? | Scn/Fsc | 第2個ITL | ||||||||||||||
| 00018050h | D7 | 1 | 9 | 0 | 0 | 80 | 0 | 0 | 3D | 14 | 15 | 0 | 0 | 0 | 0 | 0 |
| ? | 第2個ITL | 空閑8個bytes | ||||||||||||||
| ? 空閑字節:? 8bytes。若用ASSM則需要在此+8字節,否則不需要(未驗證) ? | ||||||||||||||||
| 00018060h | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 0 | FF | FF | 18 | 0 | 0E | 8 | F6 | 7 |
| ? | 空閑 | flag | ntab | nrow | frre | fsbo | fseo | avsp | ||||||||
| ? struct kdbh ?14 bytes?????? @100??? :此結構共14字節,塊內偏移量100字節 ??? ub1 kdbhflag??????????? @100?? ?:N=pctfree hit(clusters); F=do not put on freelist; K=flushable cluster keys? ??? b1 kdbhntab???????????? @101?? ?:Number of tables (>1 in clusters) ??? b2 kdbhnrow???????????? @102??? :block 有多少條數據 ??? sb2 kdbhfrre??????????? @104??? :First free row entry index; -1 = you have to add one ??? sb2 kdbhfsbo??????????? @106??? :空閑空間的開始 ??? sb2 kdbhfseo??????????? @108??? :空閑空間的結尾 ??? b2 kdbhavsp???????????? @110??? :塊中可用空閑空間,單位是bytes ??? b2 kdbhtosp???????????? @112??? :塊中總可用空間 ? | ||||||||||||||||
| 00018070h | F6 | 7 | 0 | 0 | 3 | 0 | BF | 17 | 0E | 8 | E7 | 0F | 3D | 5A | 7 | 52 |
| ? | kdbhtosp | kdbtoffs | kdbtnrow | rowoffs1 | Rowoffs2 | Rowoffs3 | freespace | |||||||||
| ? Table Directory ?Entry ?Structure : ? struct kdbt[1], 4 bytes???? @114??????? ??? b2 kdbtoffs???????????? @114???? b2 kdbtnrow???????????? @116 ? Row Directory : ? sb2? kdbr[3] ???@118 : --共3(記錄條數為變量)條記錄,每個記錄長2 bytes ,塊內偏移量118 bytes 。 ?? ?row offs1 ?? ?row offs2 ?? ?row offs3 ? | ||||||||||||||||
| ……. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ? | freespace | |||||||||||||||
| ? ub1 freespace[2038]?? @124?? --共2038 bytes,塊內偏移量124 bytes ???????????????????????????? --[2038] = kdbh.kdbhavsp(十進制)? ???????????????????????????? --@124 = kdbh.fsbo(十進制)+ ( 20 + 24 + 24*ITLS + 8 ) ? | ||||||||||||||||
| 00018870h | 0 | 0 | 2C | 0 | 2 | 2 | C1 | 4 | FE | D0 | 7 | 61 | 20 | 20 | 20 | 20 |
| ? | freespace | flag | lock | ccnt | lgth | date | ? | lgth | date | |||||||
| ? ub1 rowdata[6026] ???@2162? --共6026 bytes,塊內偏移量2162 bytes ??????????????????????????? --@2162 =? ( 20 + 24 + 24*ITLS + 8 ) + kdbh.fsbo(十進制) + freespace[2038] ??????????????????????????? --注:本數據塊的起始位置 18000h( 十六進制文件的offset ),塊內偏移量2162,故rowdata在本塊的最后一條(數據塊中的數據是從底? 向上增長的)數據位置為:00018872h 。實際上:此條數據已被刪除,select是查不到的,oracle并未從塊中立即清楚delete的數據。從dump文件中計算最后一行數據( 未被刪除的 )位置:0001904b h ? | ||||||||||||||||
| 00019040h | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 2c | 0 | 2 | 1 | 80 |
| 00019050h | fe | D0 | 7 | 61 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 |
| ? 行記錄結構: ????? flag:? 1byte。行狀態標志 ????? lock:? 1byte。同ITL 的lck相對應 表示這行是否被 lock 了 ????? ccnt:? 1byte。該行數據幾列 ????????????? 以上三個字節對應kdrh結構中的(ub1 kdrhflag,ub1 kdrhlock,ubl kdrhccnt) ????? Lgth:? 列的數據的長度是多少。 ???????????? 1. 0xfa ( 250 bytes ) 其實0xfb,0xfc,0xfd 也同樣是250bytes ???????????? 2. 0xfe fb 00 ( 0xfb 00 表示的251 bytes 0xfe表示row的長度超過了250 bytes) ???????????? 3. 0xff 表示number 的 null 這也是oracle中null的表現形式排序的時候null最大了 ??????????? 字段的數據超過250字節是就用3bytes來表示字段的長度。因為如果是long類型,它的字段再長 ??????????? 它在這個block中的數據的長度不會超過64K 。所以最長用3bytes來表示行的長度已經夠了.再長就鏈接行了 ????? Data:? 實際字段值 ? ? | ||||||||||||||||
| ……. | 0 | 2c | 0 | 2 | 2 | C1 | 4 | fe | D0 | 7 | 61 | 20 | 20 | 20 | 20 | 20 |
| ? | date | |||||||||||||||
| 00019ff0h | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 3 | 6 | 8b | 61 |
| ? | ? | block tail | ||||||||||||||
| ? ub4 tailchk???? @8188? --塊尾部的4 bytes ???? 第1 byte : 對應開始的 seq ???? 第2 byte : 對應開始的 type ?? 第3,4 byte : 對應開始的SCN的末2位 ? | ||||||||||||||||
| ? 下面結合dump文件對數據塊進行分析: The Cache Header : ? ....... ? Start dump data blocks tsn: 14 file#: 14 minblk 12 maxblk 12 ? buffer tsn: 14 rdba: 0x0380000c (14/12) ? scn: 0x0000.0015618b seq: 0x03 flg: 0x04 tail: 0x618b0603 ? frmt: 0x02 chkval: 0xaf9d type: 0x06=trans data ? Hex dump of block: st=0, typ_found=1 注:buffer tsn :14??? 這個記錄只是在dump文件中有記錄,在實際的block 中是沒有記錄的。
The Transaction Header : ? Block header dump:? 0x0380000c ?Object id on Block? Y ?seg/obj: 0xd004? csc: 0x00.15516a? itc: 2? flg: E? typ: 1 - DATA ???? brn: 0? bdba: 0x3800009 ver: 0x01 opc: 0 ???? inc: 0? exflg: 0 注:brn,ver,inc,exflg 等字段在數據塊中未找到相應字節
Itl?????????? Xid????????????????? Uba???????? Flag? Lck??????? Scn/Fsc 0x01?? 0x0003.005.00000274? 0x00800343.01a2.29? C---??? 0? scn 0x0000.001510ae 0x02?? 0x0002.00c.00000251? 0x00800a48.01d7.09? C---??? 0? scn 0x0000.0015143d
data_block_dump,data header at 0xc555a64 =============== tsiz: 0x1f98??? ?--8k block: 8192-20(block head)-24(Transaction Header)-24*2(ITL)-8(空閑塊)-4(block tail)=8088(0x1f98) hsiz: 0x18?????? -- Data header size? 數據塊頭20個字節+數據塊尾4個字節=24字節(0x14)????? ?????????? pbl: 0x0c555a64? --Pointer to buffer holding the block????????????????????????????? ????????????????????????????????????????????????????? 注:tsiz,hsiz,pbl并未存儲在數據塊中???????????????????????????????????????? ????????????????????????????????????????????????????? bdba: 0x0380000c 76543210 flag=-------- ntab=1 nrow=3 frre=-1 fsbo=0x18???????????????????????? --空閑空間起始位置距離本塊頭的距離:? 0x18 + ( 20 + 24 + ITL*2 + 8 ) fseo=0x80e??????????????????????? --空閑空間結尾位置距離本塊頭的距離: 0x80e + ( 20 + 24 + ITL*2 + 8 ) avsp=0x7f6??????????????????????? --塊中可用空閑空間 avsp = fseo - fsbo tosp=0x7f6??????????????????????? --塊中總可用空間 0xe:pti[0] nrow=3 offs=0 0x12:pri[0] offs=0x17bf?????????? --第1行行頭塊內偏移字節:0x17bf + ( 20 + 24 + ITL*2 + 8 ) 0x14:pri[1] offs=0x80e 0x16:pri[2] offs=0xfe7??????????? --最后一條記錄塊內偏移字節:0xfe7+( 20 + 24 + ITL*2 + 8 ) (表格中說明:0001904b h) block_row_dump: tab 0, row 0, @0x17bf tl: 2009 fb: --H-FL-- lb: 0x0? cc: 2 col? 0: [ 2]? c1 04 col? 1: [2000] 61 20 20…… tab 0, row 1, @0x80e tl: 2009 fb: --H-FL-- lb: 0x0? cc: 2 col? 0: [ 2]? c1 04 col? 1: [2000] 61 20 20…… tab 0, row 2, @0xfe7 tl: 2008 fb: --H-FL-- lb: 0x0? cc: 2 col? 0: [ 1]? 80 col? 1: [2000] 61 20 20…… ? ? | ||||||||||||||||
?文檔附件位置:http://www.itpub.net/thread-1820926-1-1.html
總結
以上是生活随笔為你收集整理的Oracle 摘去数据块的面纱的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习Windows2008——常用工具及
- 下一篇: 从C#到Objective-C,循序渐进