BBED使用手册
BBED是Oracle提供的块编辑器,借助BBED,可以帮助我们更好的理解Oracle的Block的结构。当然,反过来说,也只有更加理解块的结构,才能更好的利用BBED完成某些特殊情况下的灾难恢复。
以下是BBED各个命令的使用,翻译自BBED手册。
set dba:
设置当前编辑/浏览的数据块地址,dba的格式:file_id,block_id,如选择4号数据文件的16号数据块:set dba 4,16
set filename
设置当前编辑/浏览的文件
set filename '/u01/app/oracle/oradata/orcl/example01.dbf'
set file
设置当前编辑/浏览的文件号
BBED> set file 4
FILE# 4
set block
设置当前编辑/浏览的块号
BBED> set block 16
BLOCK# 16
前面加(+)/(-)号表示对当前块号做加减运算
BBED> set block +3
BLOCK# 19
BBED> set block -3
BLOCK# 16
set offset
设置dump显示数据的起始字节偏移量
BBED> set offset 20
OFFSET 20
BBED> set offset +2
OFFSET 22
BBED> set offset -3
OFFSET 19
BBED> d
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 19 to 530 Dba:0x01000010
------------------------------------------------------------------------
00010000 00cac700 00d9bf06 00000000 00020032 00090000 01030011 00f20000
00945780 00c8002d 00042000 00dbbf06 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000104 00ffff1a 003c1f22 1f221f00
0004007e 1f681f54 1f3c1f00 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
set blocksize
设置当前数据文件的块大小,必须是当前数据文件的块大小,否则报错
BBED> set blocksize 16384
BBED-00307: incorrect blocksize (8192) or truncated file
BBED> set blocksize 8192
BLOCKSIZE 8192
set listfile
设置使用的listfile文件,listfile文件包含bbed所要编辑的数据文件列表
BBED> show
FILE# 1
BLOCK# 1
OFFSET 0
DBA 0x00400001 (4194305 1,1)
FILENAME /u01/app/oracle/oradata/orcl/system01.dbf
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
BBED> set listfile 'filelist.txt.bak'
LISTFILE filelist.txt.bak
listfile文件每行的格式为:file_id file_name file_bytes,如下
1 /u01/app/oracle/oradata/orcl/system01.dbf 503316480
2 /u01/app/oracle/oradata/orcl/undotbs01.dbf 31457280
3 /u01/app/oracle/oradata/orcl/sysaux01.dbf 241172480
4 /u01/app/oracle/oradata/orcl/users01.dbf 5242880
5 /u01/app/oracle/oradata/orcl/example01.dbf 104857600
可以使用SQL语句生成
select file#||' '||name||' '||bytes from v$datafile;
set count
设置dump命令显示的对应数据块的字节数,默认为512个字节。如果需要看到一个8k数据块的整个块内容,可以设置count为8192或者更大
BBED> set count 8192
COUNT 8192
BBED> d
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 15 Offsets: 0 to 8191 Dba:0x0100000f
------------------------------------------------------------------------
06a20000 0f000001 dbbf0600 00000104 4b380000 01000000 cac70000 d9bf0600
00000000 02003200 09000001 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 ffff0e00 981f8a1f 8a1f0000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
---------------------此处省略n行---------------------------------------
00000000 00000000 00000000 00000000 00000000 00000000 00000000 0106dbbf
<32 bytes per line>
set ibase
设置使用set block,set file,set offset使用的进制:Dec-十进制 Hex-十六进制 Oct-八进制
BBED> show ibase
IBASE Dec
BBED> set ibase hex
IBASE Hex
BBED> set block a
BLOCK# 10
BBED> set ibase oct
IBASE Oct
BBED> set block 9
BBED-00202: invalid parameter (9)
BBED> set block 8
BBED-00202: invalid parameter (8)
BBED> set block 7
BLOCK# 7
set mode
设置bbed模式是编辑还是浏览,浏览模式无法对数据块进行修改
BBED> set mode browse
MODE Browse
BBED> set mode edit
MODE Edit
show
显示当前bbed的配置[通过set命令设置的选项]
BBED> show
FILE# 04
BLOCK# 07
OFFSET 00
DBA 0x01000007 (16777223 4,7)
FILENAME /u01/app/oracle/oradata/orcl/users01.dbf
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Oct
OBASE Oct
WIDTH 80
COUNT 8192
LOGFILE log.bbd
SPOOL No
info
显示当前的listfile内容
BBED> info
File# Name Size(blks)
----- ---- ----------
1 /u01/app/oracle/oradata/orcl/system01.dbf 61440
2 /u01/app/oracle/oradata/orcl/undotbs01.dbf 3840
3 /u01/app/oracle/oradata/orcl/sysaux01.dbf 29440
4 /u01/app/oracle/oradata/orcl/users01.dbf 640
5 /u01/app/oracle/oradata/orcl/example01.dbf 12800
map
显示块结构
显示当前块
BBED> map
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 12 Dba:0x0100000c
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[0], 0 bytes @114
sb2 kdbr[0] @114
ub1 freespace[8074] @114
ub1 rowdata[0] @8188
ub4 tailchk @8188
显示当前块结构并显示结构体的每个字段
BBED> map /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 12 Dba:0x0100000c
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
ub1 type_kcbh @0
ub1 frmt_kcbh @1
ub1 spare1_kcbh @2
ub1 spare2_kcbh @3
ub4 rdba_kcbh @4
ub4 bas_kcbh @8
ub2 wrp_kcbh @12
ub1 seq_kcbh @14
ub1 flg_kcbh @15
ub2 chkval_kcbh @16
ub2 spare3_kcbh @18
struct ktbbh, 72 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
b2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl[2], 48 bytes @44
struct kdbh, 14 bytes @100
ub1 kdbhflag @100
b1 kdbhntab @101
b2 kdbhnrow @102
sb2 kdbhfrre @104
sb2 kdbhfsbo @106
sb2 kdbhfseo @108
b2 kdbhavsp @110
b2 kdbhtosp @112
struct kdbt[0], 0 bytes @114
b2 kdbtoffs @114
b2 kdbtnrow @116
sb2 kdbr[0] @114
ub1 freespace[8074] @114
ub1 rowdata[0] @8188
ub4 tailchk @8188
显示指定数据块的结构
BBED> map /v dba 4,16
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 14 Dba:0x0100000e
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
ub1 type_kcbh @0
ub1 frmt_kcbh @1
ub1 spare1_kcbh @2
ub1 spare2_kcbh @3
ub4 rdba_kcbh @4
ub4 bas_kcbh @8
ub2 wrp_kcbh @12
ub1 seq_kcbh @14
ub1 flg_kcbh @15
ub2 chkval_kcbh @16
ub2 spare3_kcbh @18
struct ktbbh, 72 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
b2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl[2], 48 bytes @44
struct kdbh, 14 bytes @100
ub1 kdbhflag @100
b1 kdbhntab @101
b2 kdbhnrow @102
sb2 kdbhfrre @104
sb2 kdbhfsbo @106
sb2 kdbhfseo @108
b2 kdbhavsp @110
b2 kdbhtosp @112
struct kdbt[0], 0 bytes @114
b2 kdbtoffs @114
b2 kdbtnrow @116
sb2 kdbr[0] @114
ub1 freespace[8074] @114
ub1 rowdata[0] @8188
ub4 tailchk @8188
dump
显示数据块内容[十六进制]
BBED> d
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 14 Offsets: 0 to 255 Dba:0x0100000e
------------------------------------------------------------------------
06a20000 0e000001 dbbf0600 00000104 a8380000 01000a00 cac70000 d9bf0600
0000e81f 021f3200 09000001 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 ffff0e00 981f8a1f 8a1f0000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
同时显示二进制转换后的字符串
BBED> set offset 8096
OFFSET 8096
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8096 to 8191 Dba:0x01000010
-------------------------------------------------------
2c010302 c1290a4f 50455241 54494f4e l ,...?.OPERATION
5306424f 53544f4e 2c010302 c11f0553 l S.BOSTON,...?.S
414c4553 07434849 4341474f 2c010302 l ALES.CHICAGO,...
c1150852 45534541 52434806 44414c4c l ?.RESEARCH.DALL
41532c01 0302c10b 0a414343 4f554e54 l AS,...?.ACCOUNT
494e4708 4e455720 594f524b 0606dbbf l ING.NEW YORK..劭
<16 bytes per line>
也可以在dump命令中指定dba,offset和count
BBED> d /v dba 4,16 offset 8097 count 100
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8097 to 8191 Dba:0x01000010
-------------------------------------------------------
010302c1 290a4f50 45524154 494f4e53 l ...?.OPERATIONS
06424f53 544f4e2c 010302c1 1f055341 l .BOSTON,...?.SA
4c455307 43484943 41474f2c 010302c1 l LES.CHICAGO,...
15085245 53454152 43480644 414c4c41 l ..RESEARCH.DALLA
532c0103 02c10b0a 4143434f 554e5449 l S,...?.ACCOUNTI
4e47084e 45572059 4f524b06 06dbbf l NG.NEW YORK..劭
<16 bytes per line>
print
显示数据块中offset位置的块结构
BBED> set dba 4,16
DBA 0x01000010 (16777232 4,16)
BBED> set offset 0
OFFSET 0
BBED> p
kcbh.type_kcbh
--------------
ub1 type_kcbh @0 0x06
BBED> set offset 8190
OFFSET 8190
BBED> p
tailchk
-------
ub4 tailchk @8188 0xbfdb0606
BBED> p dba 4,16 offset 8190
tailchk
-------
ub4 tailchk @8188 0xbfdb0606
显示结构体的每个字段
BBED> p kcbh
struct kcbh, 20 bytes @0
ub1 type_kcbh @0 0x06
ub1 frmt_kcbh @1 0xa2
ub1 spare1_kcbh @2 0x00
ub1 spare2_kcbh @3 0x00
ub4 rdba_kcbh @4 0x01000010
ub4 bas_kcbh @8 0x0006bfdb
ub2 wrp_kcbh @12 0x0000
ub1 seq_kcbh @14 0x06
ub1 flg_kcbh @15 0x06 (KCBHFDLC, KCBHFCKV)
ub2 chkval_kcbh @16 0xf309
ub2 spare3_kcbh @18 0x0000
如想查看块中存储的数据行数,打印kdbh(Data Block Header)结构,Block Header结构体中包含有记录块中存储数据行数的字段kdbhnrow
BBED> p kdbh
struct kdbh, 14 bytes @100
ub1 kdbhflag @100 0x00 (NONE)
b1 kdbhntab @101 1
b2 kdbhnrow @102 4 --数据行数
sb2 kdbhfrre @104 -1
sb2 kdbhfsbo @106 26
sb2 kdbhfseo @108 7996
b2 kdbhavsp @110 7970
b2 kdbhtosp @112 7970
也可以直接打印kdbhnrow字段
BBED> p kdbhnrow
b2 kdbhnrow @102 4
print命令打印数据结构的格式如下
Unit Size | Name | Offset | Value
Unit Size中的bn表示n个字节,前缀u和s分别表示unsigned[无符号数]和signed[有符号数,用一位二进制数表示符号位]
使用指针符*查看指针类型的数据[如kdbr结构体也就是Row Directory中的指针,Row Directory中的每个记录指向Row Data部分的实际存储数据的地址],以存储scott.dept这张表的block为例,也就是dba为4,16的这个block:
Row Directory:
BBED> p kdbr
sb2 kdbr[0] @118 8062
sb2 kdbr[1] @120 8040
sb2 kdbr[2] @122 8020
sb2 kdbr[3] @124 7996
Row Directory中第一个记录指向Row Data部分的地址
BBED> p *kdbr[0]
rowdata[66]
-----------
ub1 rowdata[66] @8162 0x2c
可以使用dump命令进行验证
BBED> d /v offset 8162
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8162 to 8191 Dba:0x01000010
-------------------------------------------------------
2c010302 c10b0a41 43434f55 4e54494e l ,...?.ACCOUNTIN
47084e45 5720594f 524b0606 dbbf l G.NEW YORK..劭
<16 bytes per line>
print也可以直接使用offset指定偏移量,但没有类似dump命令的count选项
BBED> p dba 4,14 offset 100
kdbh.kdbhflag
-------------
ub1 kdbhflag @100 0x00 (NONE)
print命令还有一些输出格式控制选项,如下
/x 十六进制
/d 有符号数的十进制
/u 无符号的十进制
/o 八进制
/c 字符串
/n Oracle中的Number类型
/t Oracle中的Data类型
/i Oracle中的RowID类型
BBED> p /c rowdata
ub1 rowdata[0] @8096 ,
ub1 rowdata[1] @8097 .
ub1 rowdata[2] @8098 .
ub1 rowdata[3] @8099 .
ub1 rowdata[4] @8100
ub1 rowdata[5] @8101 )
ub1 rowdata[6] @8102 .
ub1 rowdata[7] @8103 O
ub1 rowdata[8] @8104 P
ub1 rowdata[9] @8105 E
ub1 rowdata[10] @8106 R
ub1 rowdata[11] @8107 A
ub1 rowdata[12] @8108 T
ub1 rowdata[13] @8109 I
ub1 rowdata[14] @8110 O
ub1 rowdata[15] @8111 N
ub1 rowdata[16] @8112 S
ub1 rowdata[17] @8113 .
ub1 rowdata[18] @8114 B
ub1 rowdata[19] @8115 O
ub1 rowdata[20] @8116 S
ub1 rowdata[21] @8117 T
ub1 rowdata[22] @8118 O
ub1 rowdata[23] @8119 N
ub1 rowdata[24] @8120 ,
ub1 rowdata[25] @8121 .
ub1 rowdata[26] @8122 .
-------------------------此处也省略n行----------------
examine
examine用于以16进制或者特定的格式显示行数据
BBED> x /rncc
rowdata[0] @8096
----------
flag@8096: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8097: 0x01
cols@8098: 3
col 0[2] @8099: 40
col 1[10] @8102: OPERATIONS
col 2[6] @8113: BOSTON
用于控制显示格式的开关
/b b1,ub1(byte)
/h b2,ub2(half-word)
/w b4,ub4(word)
/l b8,ub8(long)(was b4/ub4 in Oracle7)
/r Oracle table/index row
ncc指定了3列值的类型分别为Number、Char和Char
指定重复次数,如显示block中全部的4行记录
BBED> x /4rncc
rowdata[0] @8096
----------
flag@8096: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8097: 0x01
cols@8098: 3
col 0[2] @8099: 40
col 1[10] @8102: OPERATIONS
col 2[6] @8113: BOSTON
rowdata[24] @8120
-----------
flag@8120: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8121: 0x01
cols@8122: 3
col 0[2] @8123: 30
col 1[5] @8126: SALES
col 2[7] @8132: CHICAGO
rowdata[44] @8140
-----------
flag@8140: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8141: 0x01
cols@8142: 3
col 0[2] @8143: 20
col 1[8] @8146: RESEARCH
col 2[6] @8155: DALLAS
rowdata[66] @8162
-----------
flag@8162: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8163: 0x01
cols@8164: 3
col 0[2] @8165: 10
col 1[10] @8168: ACCOUNTING
col 2[8] @8179: NEW YORK
find
在block中查找指定格式的数据
查找的数据格式可以由以下格式指定
/x 十六进制
/d 十进制
/u 无符号十进制
/o 八进制
/c 字符
可以通过TOP和CURR指定搜索的起始offset
BBED> set offset 8165
OFFSET 8165
从当前的offset开始搜索
BBED> f /c DALLAS CURR
BBED-00212: search string not found
从offset为0处开始搜索
BBED> f /c DALLAS TOP
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8156 to 8191 Dba:0x01000010
------------------------------------------------------------------------
44414c4c 41532c01 0302c10b 0a414343 4f554e54 494e4708 4e455720 594f524b
0606dbbf
<32 bytes per line>
此时的offset被设置为匹配搜索的第一个位置
BBED> show offset
OFFSET 8156
使用dump命令进行验证
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8156 to 8191 Dba:0x01000010
-------------------------------------------------------
44414c4c 41532c01 0302c10b 0a414343 l DALLAS,...?.ACC
4f554e54 494e4708 4e455720 594f524b l OUNTING.NEW YORK
0606dbbf l ..劭
<16 bytes per line>
可以使用不带任何参数的find命令继续查找匹配的其他位置
copy
拷贝一个数据块至另一个数据块
BBED> copy dba 2,16 to dba 1,16
modify
以指定的数据格式修改数据块内容
modify命令指定的数据格式同find命令
/x 十六进制
/d 十进制
/u 无符号十进制
/o 八进制
/c 字符
修改block的NEW YORK为ZHEJIANG
BBED> f /c NEW TOP
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
------------------------------------------------------------------------
4e455720 594f524b 0606dbbf
<32 bytes per line>
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
-------------------------------------------------------
4e455720 594f524b 0606dbbf l NEW YORK..劭
<16 bytes per line>
BBED> m /c ZHEJIANG dba 4,16 offset 8180
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
------------------------------------------------------------------------
5a48454a 49414e47 0606dbbf
<32 bytes per line>
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
-------------------------------------------------------
5a48454a 49414e47 0606dbbf l ZHEJIANG..劭
<16 bytes per line>
sum
显示或更新checksum校验值
BBED> sum dba 4,16
Check value for File 4, Block 16:
current = 0xf309, required = 0x9603
BBED> sum dba 4,16 apply
Check value for File 4, Block 16:
current = 0x9603, required = 0x9603
push/pop
使用一个堆栈用于保存dba和offset,类似一个历史标签
BBED> push
DBA 0x01000010 (16777232 4,16)
OFFSET 8180
BBED> set dba 1,14
DBA 0x0040000e (4194318 1,14)
BBED> pop
DBA 0x01000010 (16777232 4,16)
OFFSET 8180
revert
回滚一个文件和一个block至bbed启动时的状态
不带参数将回滚bbed会话中的所有更改
BBED> revert
All changes made in this session will be rolled back. Proceed? (Y/N) n
Revert cancelled.
BBED> revert file
All changes made to this file will be rolled back. Proceed? (Y/N) n
Revert cancelled.
BBED> revert block
All changes made to this block will be rolled back. Proceed? (Y/N) n
Revert cancelled.
undo
回退上一次modify或者assign操作
verify
调用dbverify的一个函数校验block的完整性
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle/oradata/orcl/users01.dbf
BLOCK = 16
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
corrupt
标记数据块为坏块
BBED> corrupt
Block marked media corrupt.
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle/oradata/orcl/users01.dbf
BLOCK = 16
Block Checking: DBA = 16777232, Block Type = KTB-managed data block
Found block already marked corrupted
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
[使用]
修改数据块内容的内容的一般流程:
先找一张表中的一个rowid,如scott的dept表
SQL> run
1* select rowid,d.* from scott.dept d
ROWID DEPTNO DNAME LOC
------------------ ---------- -------------- -------------
AAAMfKAAEAAAAAQAAA 10 ACCOUNTING NEW YORK
AAAMfKAAEAAAAAQAAB 20 RESEARCH DALLAS
AAAMfKAAEAAAAAQAAC 30 SALES CHICAGO
AAAMfKAAEAAAAAQAAD 40 OPERATIONS BOSTON
通过rowid得到文件号和块号
SQL> select DBMS_ROWID.ROWID_RELATIVE_FNO('AAAMfKAAEAAAAAQAAA') file_id from dual;
FILE_ID
----------
4
SQL> select DBMS_ROWID.ROWID_BLOCK_NUMBER('AAAMfKAAEAAAAAQAAA') block_id from dual;
BLOCK_ID
----------
16
选择dept表上的16号block
BBED> set dba 4,16
DBA 0x01000010 (16777232 4,16)
使用map查看block结构
BBED> map
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Dba:0x01000010
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[1], 4 bytes @114
sb2 kdbr[4] @118
ub1 freespace[7970] @126
ub1 rowdata[92] @8096
ub4 tailchk @8188
设置偏移量
BBED> set offset 8096
OFFSET 8096
查看block内容
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8096 to 8191 Dba:0x01000010
-------------------------------------------------------
2c010302 c1290a4f 50455241 54494f4e l ,...?.OPERATION
5306424f 53544f4e 2c010302 c11f0553 l S.BOSTON,...?.S
414c4553 07434849 4341474f 2c010302 l ALES.CHICAGO,...
c1150852 45534541 52434806 44414c4c l ?.RESEARCH.DALL
41532c01 0302c10b 0a414343 4f554e54 l AS,...?.ACCOUNT
494e4708 4e455720 594f524b 0606dbbf l ING.NEW YORK..劭
<16 bytes per line>
查找NEW YORK,并将其修改为ZHEJIANG
BBED> f /c NEW TOP
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
------------------------------------------------------------------------
4e455720 594f524b 0606dbbf
<32 bytes per line>
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
-------------------------------------------------------
4e455720 594f524b 0606dbbf l NEW YORK..劭
<16 bytes per line>
BBED> m /c ZHEJIANG dba 4,16 offset 8180
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
------------------------------------------------------------------------
5a48454a 49414e47 0606dbbf
<32 bytes per line>
BBED> d /v
File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
Block: 16 Offsets: 8180 to 8191 Dba:0x01000010
-------------------------------------------------------
5a48454a 49414e47 0606dbbf l ZHEJIANG..劭
<16 bytes per line>
在修改数据块之后,重新计算并更新checksum
BBED> sum dba 4,16
Check value for File 4, Block 16:
current = 0xf309, required = 0x9603
BBED> sum dba 4,16 apply
Check value for File 4, Block 16:
current = 0x9603, required = 0x9603
此时数据块已被修改,查询业务表验证
SQL> run
1* ALTER SYSTEM FLUSH BUFFER_CACHE
System altered.
SQL> select rowid,d.* from scott.dept d;
ROWID DEPTNO DNAME LOC
------------------ ---------- -------------- -------------
AAAMfKAAEAAAAAQAAA 10 ACCOUNTING ZHEJIANG
AAAMfKAAEAAAAAQAAB 20 RESEARCH DALLAS
AAAMfKAAEAAAAAQAAC 30 SALES CHICAGO
AAAMfKAAEAAAAAQAAD 40 OPERATIONS BOSTON