数据块dump

首先在确定要dumpblock在哪个数据文件上,是block_id是多少。可以通过dba_extents视图或rowid等信息得到。

Restricted Rowid

 
  ----------------------------------------
  | BBBBBBBB . RRRR . FFFF |
  ------------------------------------------
              /             /         /
               |                |           |
               |                |            --------------------File Number
               |                 ------------------------------Row Number
                --------------------------------------------Block Number

Oracle 8 Rowid

 ------------------------------------------------
 | OOOOOO . FFF . BBBBBB . SSS |
  ------------------------------------------------
           /             /        /         /
            |                |           |           |
            |                |           |             -----------Slot Number(Row#)
            |                |            ----------------------Block Number
            |                 --------------------------------Relative File Number
             ----------------------------------------------Data Object Number

rowid的定义规则,第7~9位是表示的是数据文件,而10~15位表示的是在这个数据文件中的第几个BLOCK。
rowid编码相当于64进制。用A~Z a~z 0~9 + /共64个字符表示。A表示0,B表示1,……,a表示26,……,0表示52,……,
+表示62,/表示63。)

1. 操作系统(Unix)dump

dd bs=<db_block_size> if=<file_name> | skip=(block-1) count=1 | od -x

2. 数据库级的dump

alter system dump datafile <file_id> block <block_id>

3. dump结果的说明

Block header dump:  0x01000316    <---- Relative Data Block Address
Object id on Block? Y
seg/obj: 0x16cb  csc: 0x00.2b506360  itc: 1  flg: -  typ: 1 - DATA
           ^               ^              ^       ^       ^
           |               |              |       |        ------typ: 1 = DATA 2 = INDEX
           |               |              |       --------------flg: O = On Freelist
           |               |              ---------------------itc: Number of ITL slots
           |               ----------------------------------csc: SCN of last block cleanout
           ------------------------------------------------Seg/Obj ID in Dictionary
fsl: 0  fnx: 0x0 ver: 0x01
     ^        ^
     |        --------------------------------------------DBA of next block on freelist
     ----------------------------------------------------ITL TX freelist slot

Itl          Xid                                          Uba                Flag  Lck        Scn/Fsc
0x01   xid:  0x0002.04c.0003c689    uba: 0x0081744b.43e1.25 --U-  285  fsc 0x0000.2b506537
==> Itl
ITL Index No.(No of ITLS determined by INITRANS and MAXTRANS)
==> Xid
Transaction ID(Undo Seg.Slot.Wrap)
==> Uba
Undo Adderss(Undo DBA.SeqNo.RecordNo)
==> Flag
C=Committed  U=Committed Upper Bound  T=Active at CSC
B=Rollback of this UBA gives before image of ITL
Flag combinations include:
  CB--  Tx is Committed ,rollback of this UBA gives prev ITL
  ------  Active Tx - look at RBS header to see if really active
  --U-  Upper Bound Commit
==> Lck
Number of Rows affected by this transaction
==> Scn/Fsc
Scn=SCN of commited TX, Fsc=Free Space Credit(bytes)
Fsc overlaps the SCN Wrap when present
data_block_dump
===============
tsiz: 0x1fb8                 ==>Total data area size
hsiz: 0x24c                  ==>Data header size
pbl: 0x1101cb044             ==>Pointer to buffer holding the block
bdba: 0x01000316             ==>Block relative data block address(RDBA)
flag=-----------             ==>N=pctfree hit(Clusters),
                      F=Don't put on freelist 
                      K=flushable cluster keys
ntab=1                       ==>Number of tables(>1 in cluster)
nrow=285                     ==>Number of ROWS
frre=-1                      ==>First free row index entry.
                     -1=you have to add one
fsbo=0x24c                   ==>Free Space Begin offset
fseo=0x582                   ==>Free Space End offset
avsp=0x336                   ==>Available space in the block
tosp=0x336                   ==>Total available space when all TXs commit
0xe:pti[0] nrow=285 offs=0   ==>Number of ROWS for first table
block_row_dump:
tab 0, row 0, @0x94f         ==> table 0, row 0 offset
tl: 32 fb: --H-FL-- lb: 0x1 cc: 2
 ^      ^            ^       ^
 |      |            |       ------Number of columns in this ROW piece
 |      |            -------------Lock byte - ITL entry that has this row locked
 |      ------------------------Flag byte: H: Head of row piece , K: Cluster key
  |                                                 C: Cluster table member, D: Deleted row, 
 |                         F: First data piece,L: Last data piece,
  |                                                 P: First column cintinues from previous row
  |                                                 N:Last column cintinues in next piece          
   --------------------------------Row Size(header + data)
 
col  0: [ 4]  c3 03 3d 07
col  1: [23]  44 42 4d 53 5f 41 51 5f 53 59 53 5f 45 58 50 5f 41 43 54 49 4f 4e 53

4.利用dump函数来dump:

Date(长度 7 类型 12)

col dump_date form a35
col real_date form a35
select dump(last_ddl_time) dump_date,
to_char(last_ddl_time,'yyyy-mm-dd hh24:mi:ss') real_date
from user_objects
where rownum=1;

DUMP_DATE                           REAL_DATE
----------------------------------- ---------------------
Typ=12 Len=7: 120,102,4,13,16,48,53 2002-04-13 15:47:52

世纪120 - 100 = 20世纪和年份加100后存储
年份102 - 100 = 2
月份4月份和日期按原值存储
日期13
小时16 - 1 = 15时间均加1后存储
分钟48 - 1 = 47
53 - 1 = 52

 


Number(类型 2)

<[长度]>,符号位/指数 数字1,数字2,数字3......,数字20

正数:指数=数字1 - 193 (最高位为1是代表正数)
负数:指数=62 - 第一字节

数字1是最高有效位

正数:加1存储
负数:被101,如果总长度小于21个字节,最后加一个102(是为了排序的需要)

所存储的数值计算方法为:

把下面计算的结果加起来:

每个数字乘以100^(指数-N) (N是有效位数的顺序位,第一个有效位的N=0)

例:

select dump(123456.789) from dual;

DUMP(123456.789)
-------------------------------
Typ=2 Len=6: 195,13,35,57,79,91   

指数195 - 193 = 2
数字113 - 1 = 12*1002-0120000
数字235 - 1 = 34*1002-13400
数字357 - 1 = 56*1002-256
数字479 - 1 = 78*1002-3.78
数字591 - 1 = 90*1002-4.009
 123456.789

select dump(-123456.789) from dual;

DUMP(-123456.789)
----------------------------------
Typ=2 Len=7: 60,89,67,45,23,11,102

指数62 - 60 = 2(最高位是0,代表为负数)
数字1101 - 89 = 12*1002-0120000
数字2101 - 67 = 34*1002-13400
数字3101 - 45 = 56*1002-256
数字4101 - 23 = 78*1002-3.78
数字5101 - 11 = 90*1002-4.009
 123456.789(-)

现在再考虑一下为什么在最后加102是为了排序的需要,-123456.789在数据库中实际存储为

60,89,67,45,23,11

-123456.78901在数据库中实际存储为

60,89,67,45,23,11,91

可见,如果不在最后加上102,在排序时会出现-123456.789<-123456.78901的情况

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值