1.centos上编译安装BBED工具
[orasrv@localhost ~]$ cd $ORACLE_HOME/rdbms/lib
[orasrv@localhost ~]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
也可通过以下命令将bbed生成到$ORACLE_HOME/bin目录
[orasrv@localhost ~]$ make -f ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
$ORACLE_HOME/rdbms/lib/ssbbded.o
$ORACLE_HOME/rdbms/lib/sbbdpt.o
$ORACLE_HOME/rdbms/mesg/bbedus.msb
$ORACLE_HOME/rdbms/mesg/bbedus.msg
$ORACLE_HOME/rdbms/mesg/bbedar.msb
2.使用BBED
2.1 初始化
2.1.1配置bbed.par和filelist.txt
[orasrv@localhost ~]$ cat filelist.txt
1 /opt/orasrv/oradata/fzdb1/system01.dbf 524288000
2 /opt/orasrv/oradata/fzdb1/undotbs01.dbf 5840568320
3 /opt/orasrv/oradata/fzdb1/sysaux01.dbf 429916160
4 /opt/orasrv/oradata/fzdb1/users01.dbf 5242880
5 /opt/orasrv/oradata/fzdb1/ts_account01.dbf 1308622848
6 /opt/orasrv/oradata/fzdb1/ts_passport01.dbf 201326592
7 /opt/orasrv/oradata/fzdb1/ts_game01.dbf 33554432
8 /opt/orasrv/oradata/fzdb1/ts_sales.dbf 33554432
9 /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf 134217728
[orasrv@localhost ~]$ cat bbed.par
blocksize=8192
listfile=/home/orasrv/filelist.txt
mode=edit
或者可以登录BBED后使用set命令来设置
BBED> set blocksize 8192
BLOCKSIZE 8192
BBED> set listfile '/home/orasrv/filelist.txt'
设置屏幕显示宽度
BBED> set width 200
WIDTH 200
设置dump命令显示的字节数,默认是512bytes
BBED> set count 512
COUNT 512
设置模式
BBED> set mode browse
MODE Browse
BBED> set mode edit
MODE Edit
2.2 基本命令
[orasrv@localhost lib]$ ./bbed parfile=/home/orasrv/bbed.par
Password: ---默认密码为blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Thu May 9 15:08:07 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
2.2.1显示在filelist中配置的可以查看或编辑的数据文件
BBED> info
File# Name Size(blks)
----- ---- ----------
1 /opt/orasrv/oradata/fzdb1/system01.dbf 64000
2 /opt/orasrv/oradata/fzdb1/undotbs01.dbf 188672
3 /opt/orasrv/oradata/fzdb1/sysaux01.dbf 52480
4 /opt/orasrv/oradata/fzdb1/users01.dbf 640
5 /opt/orasrv/oradata/fzdb1/ts_account01.dbf 159744
6 /opt/orasrv/oradata/fzdb1/ts_passport01.dbf 24576
7 /opt/orasrv/oradata/fzdb1/ts_game01.dbf 4096
8 /opt/orasrv/oradata/fzdb1/ts_sales.dbf 4096
9 /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf 16384
2.2.2 set具体使用
来看看9号数据文件中的一些数据记录
ZJTEST@fzdb1 >select rowid,dbms_rowid.rowid_relative_fno(rowid) rel_fno,dbms_rowid.rowid_block_number(rowid) blockno,
dbms_rowid.rowid_row_number(rowid) rowno from objtest where rownum<10;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- ---------- ----------
AAAkbQAAJAAAAANAAA 9 13 0
AAAkbQAAJAAAAANAAB 9 13 1
AAAkbQAAJAAAAANAAC 9 13 2
AAAkbQAAJAAAAANAAD 9 13 3
AAAkbQAAJAAAAANAAE 9 13 4
AAAkbQAAJAAAAANAAF 9 13 5
AAAkbQAAJAAAAANAAG 9 13 6
AAAkbQAAJAAAAANAAH 9 13 7
AAAkbQAAJAAAAANAAI 9 13 8
9 rows selected.
Elapsed: 00:00:00.09
下面在BBED中set到该块,注意文件号必须是已经记录在filelist.txt中的
BBED> set dba 9,13
DBA 0x0240000d (37748749 9,13)
如果正确找到指定块的话,BBED会返回该块的RDBA,即上面的37748749,下面验证一下
ZJTEST@fzdb1 >select dbms_utility.make_data_block_address(9,13) from dual;
DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS(9,13)
------------------------------------------
37748749
或者直接set filename
BBED> set filename '/opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf' ---注意单引号
FILENAME /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf
或者先set file,然后set block
BBED> set file 9
FILE# 9
BBED> set block 14
BLOCK# 14
BBED> set block +10
BLOCK# 24
BBED> set block -5
BLOCK# 19
下面设置块内偏移量
BBED> set offset 20
OFFSET 20
BBED> set offset +10
OFFSET 30
2.2.3show命令,查看当前配置选项
BBED> show
FILE# 9
BLOCK# 19
OFFSET 30
DBA 0x02400013 (37748755 9,19)
FILENAME /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf
BIFILE bifile.bbd
LISTFILE /home/orasrv/filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
2.2.4 map命令,显示块内结构、数据,可以使用/v显示详细信息
BBED> map
File: /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf (9)
Block: 19 Dba:0x02400013
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 96 bytes @20
struct kdbh, 14 bytes @124
struct kdbt[1], 4 bytes @138
sb2 kdbr[80] @142
ub1 freespace[822] @302
ub1 rowdata[7064] @1124
ub4 tailchk @8188
2.2.5 dump某个块指定偏移量的详细内容
BBED> dump /v offset 32 count 256
File: /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf (9)
Block: 19 Offsets: 32 to 287 Dba:0x02400013
-------------------------------------------------------
04000000 03003200 09004002 ffff0000 l ......2...@.....
00000000 00000000 00000000 00800400 l ................
2d67de89 00000000 00000000 00000000 l -g..............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00015000 l ..............P.
ffffb200 e8033603 36030000 5000291f l ......6.6...P.).
cd1e751e 201ecd1d 7a1d261d d21c7c1c l ..u. ...z.&...|.
1f1cc41b 711b1e1b c11a6e1a 0d1abe19 l ....q.....n.....
61190d19 b2185b18 0e18bc17 6e171b17 l a.....[.....n...
ca167416 1f16cb15 7a151915 c7146f14 l ..t.....z.....o.
1c14c913 76132213 c9127812 2012ce11 l ....v."...x. ...
78112011 c5106c10 1210b50f 5a0ff50e l x. ...l.....Z...
970e3b0e e10d870d 2a0dc40c 6c0c130c l ..;.....*...l...
ba0b630b 0b0bb40a 590a000a a5094809 l ..c.....Y.....H.
f0089408 3d08dc07 7c071c07 be066606 l ....=...|.....f.
<16 bytes per line>
2.2.6 print命令
BBED> p kdbh
struct kdbh, 14 bytes @124
ub1 kdbhflag @124 0x00 (NONE)
b1 kdbhntab @125 1
b2 kdbhnrow @126 80
sb2 kdbhfrre @128 -1
sb2 kdbhfsbo @130 178
sb2 kdbhfseo @132 1000
b2 kdbhavsp @134 822
b2 kdbhtosp @136 822
BBED> p kdbhnrow
b2 kdbhnrow @126 80
BBED> p kdbr
sb2 kdbr[0] @142 7977
sb2 kdbr[1] @144 7885
sb2 kdbr[2] @146 7797
sb2 kdbr[3] @148 7712
sb2 kdbr[4] @150 7629
sb2 kdbr[5] @152 7546
sb2 kdbr[6] @154 7462
sb2 kdbr[7] @156 7378
sb2 kdbr[8] @158 7292
sb2 kdbr[9] @160 7199
sb2 kdbr[10] @162 7108
sb2 kdbr[11] @164 7025
sb2 kdbr[12] @166 6942
sb2 kdbr[13] @168 6849
sb2 kdbr[14] @170 6766
sb2 kdbr[15] @172 6669
sb2 kdbr[16] @174 6590
sb2 kdbr[17] @176 6497
sb2 kdbr[18] @178 6413
sb2 kdbr[19] @180 6322
sb2 kdbr[20] @182 6235
sb2 kdbr[21] @184 6158
sb2 kdbr[22] @186 6076
sb2 kdbr[23] @188 5998
sb2 kdbr[24] @190 5915
sb2 kdbr[25] @192 5834
sb2 kdbr[26] @194 5748
sb2 kdbr[27] @196 5663
sb2 kdbr[28] @198 5579
sb2 kdbr[29] @200 5498
sb2 kdbr[30] @202 5401
sb2 kdbr[31] @204 5319
sb2 kdbr[32] @206 5231
sb2 kdbr[33] @208 5148
sb2 kdbr[34] @210 5065
sb2 kdbr[35] @212 4982
sb2 kdbr[36] @214 4898
sb2 kdbr[37] @216 4809
sb2 kdbr[38] @218 4728
sb2 kdbr[39] @220 4640
sb2 kdbr[40] @222 4558
sb2 kdbr[41] @224 4472
sb2 kdbr[42] @226 4384
sb2 kdbr[43] @228 4293
sb2 kdbr[44] @230 4204
sb2 kdbr[45] @232 4114
sb2 kdbr[46] @234 4021
sb2 kdbr[47] @236 3930
sb2 kdbr[48] @238 3829
sb2 kdbr[49] @240 3735
sb2 kdbr[50] @242 3643
sb2 kdbr[51] @244 3553
sb2 kdbr[52] @246 3463
sb2 kdbr[53] @248 3370
sb2 kdbr[54] @250 3268
sb2 kdbr[55] @252 3180
sb2 kdbr[56] @254 3091
sb2 kdbr[57] @256 3002
sb2 kdbr[58] @258 2915
sb2 kdbr[59] @260 2827
sb2 kdbr[60] @262 2740
sb2 kdbr[61] @264 2649
sb2 kdbr[62] @266 2560
sb2 kdbr[63] @268 2469
sb2 kdbr[64] @270 2376
sb2 kdbr[65] @272 2288
sb2 kdbr[66] @274 2196
sb2 kdbr[67] @276 2109
sb2 kdbr[68] @278 2012
sb2 kdbr[69] @280 1916
sb2 kdbr[70] @282 1820
sb2 kdbr[71] @284 1726
sb2 kdbr[72] @286 1638
sb2 kdbr[73] @288 1542
sb2 kdbr[74] @290 1453
sb2 kdbr[75] @292 1357
sb2 kdbr[76] @294 1264
sb2 kdbr[77] @296 1177
sb2 kdbr[78] @298 1091
sb2 kdbr[79] @300 1000
BBED> p *kdbr[40]
rowdata[3558]
-------------
ub1 rowdata[3558] @4682 0x2c
BBED> d /v dba 9,19 offset 4682 count 128
File: /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf (9)
Block: 19 Offsets: 4682 to 4809 Dba:0x02400013
-------------------------------------------------------
2c000d06 5055424c 49430947 56244241 l ,...PUBLIC.GV$BA
434b5550 ff03c213 1bff0753 594e4f4e l CKUP.......SYNON
594d0778 6c030c01 292b0778 6c030c01 l YM.xl...)+.xl...
292b1332 3030382d 30332d31 323a3030 l )+.2008-03-12:00
3a34303a 34320556 414c4944 014e014e l :40:42.VALID.N.N
014e2c00 0d065055 424c4943 0f475624 l .N,...PUBLIC.GV$
5245434f 5645525f 46494c45 ff03c213 l RECOVER_FILE....
19ff0753 594e4f4e 594d0778 6c030c01 l ...SYNONYM.xl...
<16 bytes per line>
BBED> p /d offset 4682
rowdata[3558]
-------------
ub1 rowdata[3558] @4682 44
2.2.7 examin命令
BBED> p *kdbr[40]
rowdata[3558]
-------------
ub1 rowdata[3558] @4682 0x2c
BBED> x /rcnn
rowdata[3558] @4682
-------------
flag@4682: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@4683: 0x00
cols@4684: 13
col 0[6] @4685: PUBLIC
col 1[9] @4692: -0
col 2[0] @4702: *NULL*
col 3[3] @4703: 1826
col 4[0] @4707: *NULL*
col 5[7] @4708: -0
col 6[7] @4716: -0
col 7[7] @4724: -0
col 8[19] @4732: -53534556535056525143535343
col 9[5] @4752: -0
col 10[1] @4758: -0
col 11[1] @4760: -0
col 12[1] @4762: -0
BBED> x /3rcnn
rowdata[3558] @4682
-------------
flag@4682: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@4683: 0x00
cols@4684: 13
col 0[6] @4685: PUBLIC
col 1[9] @4692: -0
col 2[0] @4702: *NULL*
col 3[3] @4703: 1826
col 4[0] @4707: *NULL*
col 5[7] @4708: -0
col 6[7] @4716: -0
col 7[7] @4724: -0
col 8[19] @4732: -53534556535056525143535343
col 9[5] @4752: -0
col 10[1] @4758: -0
col 11[1] @4760: -0
col 12[1] @4762: -0
rowdata[3640] @4764
-------------
flag@4764: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@4765: 0x00
cols@4766: 13
col 0[6] @4767: PUBLIC
col 1[15] @4774: -0
col 2[0] @4790: *NULL*
col 3[3] @4791: 1824
col 4[0] @4795: *NULL*
col 5[7] @4796: -0
col 6[7] @4804: -0
col 7[7] @4812: -0
col 8[19] @4820: -53534556535056525143535343
col 9[5] @4840: -0
col 10[1] @4846: -0
col 11[1] @4848: -0
col 12[1] @4850: -0
rowdata[3728] @4852
-------------
flag@4852: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@4853: 0x00
cols@4854: 13
col 0[6] @4855: PUBLIC
col 1[8] @4862: -0
col 2[0] @4871: *NULL*
col 3[3] @4872: 1822
col 4[0] @4876: *NULL*
col 5[7] @4877: -0
col 6[7] @4885: -0
col 7[7] @4893: -0
col 8[19] @4901: -53534556535056525143535343
col 9[5] @4921: -0
col 10[1] @4927: -0
col 11[1] @4929: -0
col 12[1] @4931: -0
2.2.8 find命令,find命令可以用来搜索关键字。 可以从offset 0 搜索到top 或者从当前的offset 搜索到top
BBED> find /c SYS
File: /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf (9)
Block: 19 Offsets: 5804 to 5931 Dba:0x02400013
------------------------------------------------------------------------
53595353 544154ff 02c213ff 0753594e 4f4e594d 07786c03 0c01292a 07786c03
0c01292a 13323030 382d3033 2d31323a 30303a34 303a3431 0556414c 4944014e
014e014e 2c000d06 5055424c 49430d47 56245051 5f534553 53544154 ff03c212
63ff0753 594e4f4e 594d0778 6c030c01 292a0778 6c030c01 292a1332 3030382d
<32 bytes per line>
BBED> d /v dba 9,19 offset 5804 count 128
File: /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf (9)
Block: 19 Offsets: 5804 to 5931 Dba:0x02400013
-------------------------------------------------------
53595353 544154ff 02c213ff 0753594e l SYSSTAT......SYN
4f4e594d 07786c03 0c01292a 07786c03 l ONYM.xl...)*.xl.
0c01292a 13323030 382d3033 2d31323a l ..)*.2008-03-12:
30303a34 303a3431 0556414c 4944014e l 00:40:41.VALID.N
014e014e 2c000d06 5055424c 49430d47 l .N.N,...PUBLIC.G
56245051 5f534553 53544154 ff03c212 l V$PQ_SESSTAT....
63ff0753 594e4f4e 594d0778 6c030c01 l c..SYNONYM.xl...
292a0778 6c030c01 292a1332 3030382d l )*.xl...)*.2008-
<16 bytes per line>
2.2.9 copy命令
BBED> copy dba 9,19 to dba 9,29
2.2.10 modify(m)命令
BBED> modify /c dmm dba 1, 115362 offset 8155
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
------------------------------------------------------------------------
646d6d65 206c696b 65204f72 61636c65 212c01010c446176 65206973 20444241
21020616 b3
<32 bytes per line>
--dump 验证一下
BBED> d /v dba 1,115362 offset8155 count 128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
-------------------------------------------------------
646d6d65 206c696b 65204f72 61636c65 l dmme like Oracle
212c0101 0c446176 65206973 20444241 l!,...Dave is DBA
21020616 b3 l !...3
<16 bytes per line>
下面sum被修改的块,使修改生效,需要flush buffer cache
BBED> sum dba 1,115362
Check value for File 1, Block 115362:
current = 0xe5fb, required = 0xe5fb
BBED> sum dba 1,115362 apply
Check value for File 1, Block 115362:
current = 0xe5fb, required = 0xe5fb
2.2.11 revert是恢复自bbed 启动以来的所有修改
BBED> revert dba 1,115362
All changes made to this block will berolled back. Proceed? (Y/N) y
Reverted file'/u01/app/oracle/oradata/dave2/system01.dbf', block 115362
BBED> sum dba 1,115362 apply
Check value for File 1, Block 115362:
current = 0xdef7, required = 0xdef7
SYS@dave2(db2)> alter system flushbuffer_cache;
System altered.
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
Dave like Oracle!
2.2.12 undo命令,回滚最后一次修改操作
BBED> undo
2.2.13 verify命令用来验证block的完整性
BBED> verify dba 9,19
DBVERIFY - Verification starting
FILE = /opt/orasrv/oradata/fzdb1/ts_zjtest01.dbf
BLOCK = 19
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
2.2.14 currupt命令将一个block 标记为corrupt,这样db 在操作时就会跳过该block,从而避免错误。
undo 命令不能undo 一个corruption,但是revert 命令可以。
BBED> corrupt dba 9,19
Block marked media corrupt
注:以上部分转自David Dai的BBED工具介绍http://blog.csdn.net/tianlesoftware/article/details/5006580