您好,欢迎访问一九零五行业门户网

OracleStudy之案例--Oracle数据块地址(BlockAddress)

oracle study之案例--oracle 数据块地址(block address) oracle访问数据是以block为单位,本文简单介绍了如何通过block address在内存中获取所需要的block。 dba(data block address): a dba is the address of an oracle data block for access purposes
oracle study之案例--oracle 数据块地址(block address)
      oracle访问数据是以block为单位,本文简单介绍了如何通过block address在内存中获取所需要的block。
dba(data block address):
a dba is the address of an oracle data block for access purposes.
rdba (tablespace relative database block address):
rdba 是相对数据块地址,是数据所在的地址,rdba可就是rowid 中rfile#+block#
rowid:
      oracle在通过index访问时,通过rowid确定row的位置;我们都知道rowid表示一行的物理地址,一行唯一确定一个rowid,并且在使用中一般不会改变,除非rowid之后在行的物理位置发生改变的情况下才会发生变化。需要注意的是rowid并不会真正存在于表的data block中,但是他会存在于index当中,用来通过rowid来寻找表中的行数据。
     oracle8以前一个rowid占用6个字节大小的存储空间(10bit file#+22bit block#+16bit row#),那么oracle 8以后这个rowid的存储空间扩大到了10个字节(32bit object#+10bit rfile#+22bit block#+16bit row#),所以数据库中数据库文件个数的限制从整个数据库最多只能有的2^10-1个数据文件,变为了每个表空间中可以最多有2^10-1个数据文件。
     (需要注意的是:local index中存储的rowid是6个字节,而global index中存储的rowid是10个字节)
     那么增加的32bit object#这个前缀主要就是用来定位表空间的,同时这个object#其实对应的就是data_object_id,由于一个段对象只能属于一个表空间,同时data_object_id就是标识了一个段的物理存储id.因此object#+rfile#就可以唯一定位当前的rowid是在那个数据文件上了。
我们可以通过dbms_rowid这个包来转换我们的rowid成不同组成部分:
dbms_rowid.rowid_object(rowid) ---> 32bit object#dbms_rowid.rowid_relative_fno(rowid) ---> 10bit rfile#dbms_rowid.rowid_block_number(rowid) ---> 22bit block#dbms_rowid.rowid_row_number(rowid) ---> 16bit row#
案例分析:
1、通过dbms_utility转换地址
10:33:59 sys@ test1 >desc dbms_utilityfunction data_block_address_block returns number argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- dba                            number                  in function data_block_address_file returns number argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- dba                            number                  in function make_data_block_address returns number argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- file                           number                  in block                          number                  in
2、通过rowid获取rdba
11:14:36 sys@ test1 >conn scott/tigerconnected.11:14:39 scott@ test1 >select rowid,ename from emp where rownum=1;rowid              ename------------------ ----------aaaesjaaeaaaacvaaa smith11:15:05 scott@ test1 >select dbms_rowid.rowid_relative_fno(rowid) ,dbms_rowid.rowid_block_number(rowid) from emp where rownum=1;dbms_rowid.rowid_relative_fno(rowid) dbms_rowid.rowid_block_number(rowid)------------------------------------ ------------------------------------                                   4                                  149
3、通过dump获取block信息
11:42:16 sys@ test1 >alter system dump datafile 4 block 149;
system altered.
block dump from cache:
dump of buffer cache at level 4 for tsn=4, rdba=16777365
block dump from disk:
buffer tsn: 4 rdba: 0x01000095 (4/149)
scn: 0x0000.009722f6 seq: 0x01 flg: 0x04 tail: 0x22f60601
frmt: 0x02 chkval: 0x52a5 type: 0x06=trans data
hex dump of block: st=0, typ_found=1
dump of memory from 0x008e8200 to 0x008ea200
8e8200 0000a206 01000095 009722f6 04010000  [...............]
......
block header dump:  0x01000095
 object id on block? y
 seg/obj: 0x44a3  csc: 0x00.9722f6  itc: 2  flg: e  typ: 1 - data
     brn: 0  bdba: 0x1000090 ver: 0x01 opc: 0
     inc: 0  exflg: 0
 itl           xid                  uba         flag  lck        scn/fsc
0x01   0x001b.01f.0000007a  0x01c01c55.0121.23  c-u-    0  scn 0x0000.00971d50
0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000
bdba: 0x01000095
data_block_dump,data header at 0x8e8264
......
block_row_dump:
tab 0, row 0, @0x1f72
tl: 38 fb: --h-fl-- lb: 0x0  cc: 8
col  0: [ 3]  c2 4a 46
col  1: [ 5]  53 4d 49 54 48
col  2: [ 5]  43 4c 45 52 4b
col  3: [ 3]  c2 50 03
col  4
其它类似信息

推荐信息