数据|转换
数据块转储及RDBA的转换
原文链接:
http://www.eygle.com/internal/How_to_dump_datablock.htm
Tuesday, 2004-08-31 17:51 Eygle
很多时候我们在进行进一步研究时需要转储(dump)Oracle的数据块,以研究其内容,Oracle提供了很好的方式,我们通过以下例子简单说明一下:
[oracle@jumper udump]$ sqlplus "/ as sysdba"SQL*Plus: Release 9.2.0.3.0 - Production on Tue Aug 31 17:01:27 2004Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.Connected to:Oracle9i Enterprise Edition Release 9.2.0.3.0 - ProductionWith the Partitioning, OLAP and Oracle Data Mining optionsJServer Release 9.2.0.3.0 - ProductionSQL> select rowid,deptno,dname,loc from scott.dept;ROWID DEPTNO DNAME LOC------------------ ---------- -------------- -------------AAADZ7AABAAAGK6AAA 10 ACCOUNTING NEW YORKAAADZ7AABAAAGK6AAB 20 RESEARCH DALLASAAADZ7AABAAAGK6AAC 30 SALES CHICAGOAAADZ7AABAAAGK6AAD 40 OPERATIONS BOSTONSQL> select file_id,block_id,blocks from dba_extents where segment_name='DEPT'; FILE_ID BLOCK_ID BLOCKS---------- ---------- ---------- 1 25273 8SQL> alter system dump datafile 1 block min 25273 block max 25274;System altered.SQL> ![oracle@jumper udump]$ ls -ltotal 4-rw-r----- 1 oracle dba 3142 Aug 31 17:04 hsjf_ora_13674.trc[oracle@jumper udump]$ more hsjf_ora_13674.trc /opt/oracle/admin/hsjf/udump/hsjf_ora_13674.trcOracle9i Enterprise Edition Release 9.2.0.3.0 - ProductionWith the Partitioning, OLAP and Oracle Data Mining optionsJServer Release 9.2.0.3.0 - ProductionORACLE_HOME = /opt/oracle/product/9.2.0System name: LinuxNode name: jumper.hurray.com.cnRelease: 2.4.18-14Version: #1 Wed Sep 4 13:35:50 EDT 2002Machine: i686Instance name: hsjfRedo thread mounted by this instance: 1Oracle process number: 9Unix process pid: 13674, image: oracle@jumper.hurray.com.cn (TNS V1-V3)*** 2004-08-31 17:04:27.820*** SESSION ID:(8.3523) 2004-08-31 17:04:27.819Start dump data blocks tsn: 0 file#: 1 minblk 25273 maxblk 25274buffer tsn: 0 rdba: 0x004062b9 (1/25273)scn: 0x0000.0057c70d seq: 0x01 flg: 0x04 tail: 0xc70d1001frmt: 0x02 chkval: 0x12e3 type: 0x10=DATA SEGMENT HEADER - UNLIMITED Extent Control Header ----------------------------------------------------------------- Extent Header:: spare1: 0 spare2: 0 #extents: 1 #blocks: 7 last map 0x00000000 #maps: 0 offset: 4128 Highwater:: 0x004062bb ext#: 0 blk#: 1 ext size: 7 #blocks in seg. hdr's freelists: 1 #blocks below: 1 mapblk 0x00000000 offset: 0 Unlocked Map Header:: next 0x00000000 #extents: 1 obj#: 13947 flag: 0x40000000 Extent Map ----------------------------------------------------------------- 0x004062ba length: 7 nfl = 1, nfb = 1 typ = 1 nxf = 0 ccnt = 1 SEG LST:: flg: USED lhd: 0x004062ba ltl: 0x004062ba buffer tsn: 0 rdba: 0x004062ba (1/25274)scn: 0x0000.0131909b seq: 0x07 flg: 0x04 tail: 0x909b0607frmt: 0x02 chkval: 0xa8e7 type: 0x06=trans dataBlock header dump: 0x004062ba Object id on Block? Y seg/obj: 0x367b csc: 0x00.131909a itc: 2 flg: O typ: 1 - DATA fsl: 0 fnx: 0x0 ver: 0x01 Itl Xid Uba Flag Lck Scn/Fsc0x01 0x0001.02a.000003f3 0x0080000b.0188.08 C--- 0 scn 0x0000.0057c70e0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000 data_block_dump,data header at 0xadb505c===============tsiz: 0x1fa0hsiz: 0x1apbl: 0x0adb505cbdba: 0x004062ba 76543210flag=--------ntab=1nrow=4frre=-1fsbo=0x1afseo=0x1f44avsp=0x1f2atosp=0x1f2a0xe:pti[0] nrow=4 offs=00x12:pri[0] offs=0x1f860x14:pri[1] offs=0x1f700x16:pri[2] offs=0x1f5c0x18:pri[3] offs=0x1f44block_row_dump:tab 0, row 0, @0x1f86tl: 26 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 0bcol 1: [10] 41 43 43 4f 55 4e 54 49 4e 47col 2: [ 8] 4e 45 57 20 59 4f 52 4btab 0, row 1, @0x1f70tl: 22 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 15col 1: [ 8] 52 45 53 45 41 52 43 48col 2: [ 6] 44 41 4c 4c 41 53tab 0, row 2, @0x1f5ctl: 20 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 1fcol 1: [ 5] 53 41 4c 45 53col 2: [ 7] 43 48 49 43 41 47 4ftab 0, row 3, @0x1f44tl: 24 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 29col 1: [10] 4f 50 45 52 41 54 49 4f 4e 53col 2: [ 6] 42 4f 53 54 4f 4eend_of_block_dumpEnd dump data blocks tsn: 0 file#: 1 minblk 25273 maxblk 25274
很多人经常提出的一个问题是,rdba是如何转换的?
rdba: 0x004062ba (1/25274)
我们通过这个例子介绍一下.
rdba从Oracle6->Oracle7->Oracle8发生了三次改变:
在Oracle6中,rdba由6位2进制数表示,也就是说数据块最多只能有2^6=64个数据文件(去掉全0和全1, 实际上最多只能代表62个文件)
在Oracle7中,rdba中的文件号增加为10位,为了向后兼容,从Block号的高位拿出4位作为文件号的高位.这样从6->7的Rowid无需发生变化.
在Oracle8中,文件号仍然用10位表示,只是不再需要置换,为了向后兼容,同时引入了相对文件号(rfile#),所以从Oracle7到Oracle8,Rowid仍然无需发生变化.
举例说明如下:
在Oracle6中:比如: file 8, block 5689226位block号==56892 vv vvvvvvvv vvvvvvvv vvvvvvvv00100000 00000000 11011110 00111100 ^^^^^^6位文件号==8在Oracle7中:比如:File 255, block 56892 11111100 11000000 11011110 00111100 F C C 0 D E 3 C \_____/\___/\_______________________/ | | | | |Block = 0xDE3C = 56892 \_____________ | \ V V 0011 111111 = 0xFF = 255 --注意这里高位和低位要置换才能得出正确的file#在Oracle8中:比如:File 255, block 56892 11111100 11000000 11011110 00111100 F C C 0 D E 3 C \_____/\___/\_______________________/ | | | | |Block = 0xDE3C = 56892 \_____________ | \ V V 0011 1111 0011 = 03F3 = 1011 --这就是相对文件号
对于我们测试中的例子:
rdba: 0x004062ba (1/25274)
也就是:0000 0000 0100 0000 0110 0010 1011 1010
前10位为rfile#: 0000 0000 01 = 1
后22位为Block#:00 0000 0110 0010 1011 1010 = 25274