一. DBA(Data Block Address)
A Data Block Address (DBA) is the address of an Oracle data block for access purposes.
DBA一般指絕對資料塊位址. rowid用來表示一行的實體位址,一行唯一确定一個rowid,并且在使用中一般不會改變,除非rowid之後在行的實體位置發生改變的情況下才會發生變化。在rowid 中,就有一段是來表示DBA的。有關rowid的内容,參考我的Blog:
2.1 Find the DBA for a given row
Start by getting the file and block number of the row. Example:
SQL> SELECT
2 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
3 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
4 empno, ename
5 FROM emp WHERE empno = 7369;
REL_FNO BLOCKNO EMPNO ENAME
---------- ---------- ---------- ----------
4 20 7369 SMITH
2.2 convert the file and block numbers to a DBA address:
SQL> variable dba varchar2(30)
SQL>exec :dba := dbms_utility.make_data_block_address(4, 20);
PL/SQL procedure successfully completed.
SQL> print dba
DBA
--------------------------------
16777236
2.3 Convert a DBA back to file and block numbers
Example:
SQL> SELECT dbms_utility.data_block_address_block(16777236) "BLOCK",
2 dbms_utility.data_block_address_file(16777236) "FILE"
3 FROM dual;
BLOCK FILE
---------- ----------
20 4
二. RDBA(Tablespace relative database block address)
RDBA是相對資料塊位址,是資料字典(表空間及一些對象定義)所在塊的位址。
oracle 8以後,rowid的存儲空間擴大到了10個位元組(32bit object#+10bit rfile#+22bit block#+16bit row#)。rdba就是rowid中的rfile#+block#。
[email protected](rac1)> SELECT
rowid,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp WHERE empno = 7521;
ROWID REL_FNO BLOCKNO ROWNO EMPNO ENAME
------------------ ---------- ---------- ---------- ---------- ----------
AAAMfMAAEAAAAAgAAA 4 32 0 7369 SMITH
rowid = AAAMfMAAEAAAAAgAAA
BlockNo= 4
rowno =0
把這個block dump到trace:
[email protected](rac1)> alter system dump datafile 4 block 32;
System altered.
檢視目前的trace 檔案位置:
[email protected](rac1)> oradebug setmypid;
Statement processed.
[email protected](rac1)> oradebug tracefile_name
/u01/app/oracle/admin/anqing/udump/anqing1_ora_19997.trc
檢視trace file:
[[email protected] ~]$ cat /u01/app/oracle/admin/anqing/udump/anqing1_ora_19997.trc
*** 2011-06-07 11:02:30.023
Start dump data blocks tsn: 4 file#: 4 minblk 32 maxblk 32
buffer tsn: 4 rdba: 0x01000020 (4/32) -- rdba 的值
scn: 0x0000.0006bfdb seq: 0x10 flg: 0x06 tail: 0xbfdb0610
frmt: 0x02 chkval: 0x26a0 type: 0x06=trans data
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x0ED09400 to 0x0ED0B400
ED09400 0000A206 01000020 0006BFDB 06100000 [.... ...........]
ED09410 000026A0 00180001 0000C7CC 0006BFD9 [.&..............]
.....
ED094A0 00000000 00000000 00000000 00000000 [................]
Repeat 465 times
ED0B1C0 00000000 08012C00 2350C203 4C494D06 [.....,....P#.MIL]
ED0B1D0 0552454C 52454C43 4EC2034B B6770753 [LER.CLERK..NS.w.]
....
ED0B3E0 05485449 52454C43 50C2034B B4770703 [ITH.CLERK..P..w.]
ED0B3F0 0101110C 09C20201 15C102FF BFDB0610 [................]
Block header dump: 0x01000020
Object id on Block? Y
seg/obj: 0xc7cc csc: 0x00.6bfd9 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x1000019 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0003.011.000000f2 0x00805794.00c8.49 --U- 14 fsc 0x0000.0006bfdb
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
data_block_dump,data header at 0xed09464
===============
tsiz: 0x1f98
hsiz: 0x2e
pbl: 0x0ed09464
bdba: 0x01000020
76543210
flag=--------
ntab=1
nrow=14
frre=-1
fsbo=0x2e
fseo=0x1d61
avsp=0x1d33
tosp=0x1d33
0xe:pti[0] nrow=14 offs=0 -- 該塊中儲存了14條記錄。從row 0到row 13
0x12:pri[0] offs=0x1f72
0x14:pri[1] offs=0x1f47
0x16:pri[2] offs=0x1f1c
0x18:pri[3] offs=0x1ef3
0x1a:pri[4] offs=0x1ec6
0x1c:pri[5] offs=0x1e9d
0x1e:pri[6] offs=0x1e74
0x20:pri[7] offs=0x1e4c
0x22:pri[8] offs=0x1e26
0x24:pri[9] offs=0x1dfb
0x26:pri[10] offs=0x1dd5
0x28:pri[11] offs=0x1daf
0x2a:pri[12] offs=0x1d88
0x2c:pri[13] offs=0x1d61
block_row_dump:
tab 0, row 0, @0x1f72
tl: 38 fb: --H-FL-- lb: 0x1 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: [ 7] 77 b4 0c 11 01 01 01
col 5: [ 2] c2 09
col 6: *NULL*
col 7: [ 2] c1 15
tab 0, row 1, @0x1f47
tl: 43 fb: --H-FL-- lb: 0x1 cc: 8
col 0: [ 3] c2 4b 64
col 1: [ 5] 41 4c 4c 45 4e
col 2: [ 8] 53 41 4c 45 53 4d 41 4e
col 3: [ 3] c2 4d 63
col 4: [ 7] 77 b5 02 14 01 01 01
col 5: [ 2] c2 11
col 6: [ 2] c2 04
col 7: [ 2] c1 1f
tab 0, row 2, @0x1f1c
tl: 43 fb: --H-FL-- lb: 0x1 cc: 8
col 0: [ 3] c2 4c 16
col 1: [ 4] 57 41 52 44
col 2: [ 8] 53 41 4c 45 53 4d 41 4e
col 3: [ 3] c2 4d 63
col 4: [ 7] 77 b5 02 16 01 01 01
col 5: [ 3] c2 0d 33
col 6: [ 2] c2 06
col 7: [ 2] c1 1f
tab 0, row 3, @0x1ef3
...
tab 0, row 13, @0x1d61
tl: 39 fb: --H-FL-- lb: 0x1 cc: 8
col 0: [ 3] c2 50 23
col 1: [ 6] 4d 49 4c 4c 45 52
col 2: [ 5] 43 4c 45 52 4b
col 3: [ 3] c2 4e 53
col 4: [ 7] 77 b6 01 17 01 01 01
col 5: [ 2] c2 0e
col 6: *NULL*
col 7: [ 2] c1 0b
end_of_block_dump
End dump data blocks tsn: 4 file#: 4 minblk 32 maxblk 32
[[email protected] ~]$
SELECT DBMS_UTILITY.data_block_address_file (
TO_NUMBER (LTRIM (''0x01000020'', ''0x''), ''xxxxxxxx''))
AS file_no,
DBMS_UTILITY.data_block_address_block (
TO_NUMBER (LTRIM (''0x01000020'', ''0x''), ''xxxxxxxx''))
AS block_no
FROM DUAL;
FILE_NO BLOCK_NO
---------- ----------
4 32
這個和我們之前在rowid裡檢視的一緻。
剛才說了,在32這個塊裡儲存了14條row記錄,我們繼續查詢一下我們where=7521 那條:
tab 0, row 13, @0x1d61
[email protected](rac1)> select DBMS_UTILITY.data_block_address_block (TO_NUMBER (LTRIM (''0x1d61'', ''0x''),''xxxxxxxx'')) as block_no from dual;
BLOCK_NO
----------
7521
我們查詢的那條row記錄在最後一條。
整理自網絡