一,BBED概述
BBED是Oracle 内部使用的命令,所以Oracle 不提供技术支持。 为了安全,BBED设置了口令保护,默认密码为blockedit。
二,BBED的安装和使用
Oracle8i 的BBED在windows 平台下的$ORACLE_HOME/bin下可以找到,9i中似乎未随软件发布,故在windows没有这个工具,
在linux上面有,需要编译。
在9i/10g中连接生成bbed:
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
说明: 以上生成的bbed可执行文件在$ORACLE_HOME/rdbms/lib目录,可以复制到其他位置或者其他同Oracle版本的机器上运行。实验:(四步快速启动oracle bbed)
1 编译连接:
[oracle@hxy lib]$ cd $ORACLE_HOME/rdbms/lib
[oracle@hxy lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
rm -f /opt/oracle/product/10.2.0/rdbms/lib/bbed
gcc -o /opt/oracle/product/10.2.0/rdbms/lib/bbed -L/opt/oracle/product/10.2.0/rdbms/lib/ -L/opt/oracle/product/10.2.0/lib/ -L/opt/oracle/product/10.2.0/lib/stubs/ -L/usr/lib -lirc /opt/oracle/product/10.2.0/lib/s0main.o /opt/oracle/product/10.2.0/rdbms/lib/ssbbded.o /opt/oracle/product/10.2.0/rdbms/lib/sbbdpt.o `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 /opt/oracle/product/10.2.0/rdbms/lib/defopt.o -ldbtools10 -lclntsh `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lmm -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /opt/oracle/product/10.2.0/lib/sysliblist` -Wl,-rpath,/opt/oracle/product/10.2.0/lib -lm `cat /opt/oracle/product/10.2.0/lib/sysliblist` -ldl -lm -L/opt/oracle/product/10.2.0/lib
2 迁移执行文件:
复制生成的bbed到$ORACLE_HOME/bin下
[oracle@hxy lib]$ cp $ORACLE_HOME/rdbms/lib/bbed $ORACLE_HOME/bin
[oracle@hxy lib]$ cd $ORACLE_HOME/bin
[oracle@hxy bin]$ ls -ltr | grep bbed
-rwxr-xr-x 1 oracle oinstall 536161 Apr 12 12:57 bbed
或者直接执行下面的命令不执行第一步
也可通过以下命令将bbed生成到$ORACLE_HOME/bin目录
make -f ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
如下:
Linking BBED utility (bbed)
rm -f /opt/oracle/product/10.2.0/bin/bbed
gcc -o /opt/oracle/product/10.2.0/bin/bbed -L/opt/oracle/product/10.2.0/rdbms/lib/ -L/opt/oracle/product/10.2.0/lib/ -L/opt/oracle/product/10.2.0/lib/stubs/ -L/usr/lib -lirc /opt/oracle/product/10.2.0/lib/s0main.o /opt/oracle/product/10.2.0/rdbms/lib/ssbbded.o /opt/oracle/product/10.2.0/rdbms/lib/sbbdpt.o `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 /opt/oracle/product/10.2.0/rdbms/lib/defopt.o -ldbtools10 -lclntsh `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lmm -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /opt/oracle/product/10.2.0/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /opt/oracle/product/10.2.0/lib/sysliblist` -Wl,-rpath,/opt/oracle/product/10.2.0/lib -lm `cat /opt/oracle/product/10.2.0/lib/sysliblist` -ldl -lm -L/opt/oracle/product/10.2.0/lib
[oracle@hxy lib]$ ls -ltr | grep bbed
[oracle@hxy lib]$ cd $ORACLE_HOME/bin
[oracle@hxy bin]$ ls -ltr | grep bbed
-rwxr-xr-x 1 oracle oinstall 536161 Apr 12 12:59 bbed
3 配置登入信息:
(1)先获取datafile 的信息
将datafile 的信息写入一个文件,格式为:文件编号 文件名字 文件大小。可以通过如下SQL 获取:
SYS@orcl>select file#||' '||name||' '||bytes from v$datafile ;FILE#||''||NAME||''||BYTES
----------------------------------------------------------------------------------------------------
1 /opt/oracle/oradata/orcl/system01.dbf 524288000
2 /opt/oracle/oradata/orcl/undotbs01.dbf 209715200
3 /opt/oracle/oradata/orcl/sysaux01.dbf 251658240
4 /opt/oracle/oradata/orcl/user01.dbf 5242880
5 /opt/oracle/oradata/orcl/hxy01.dbf 20971520
6 /opt/oracle/oradata/orcl/hxy101.dbf 20971520
7 /opt/oracle/oradata/orcl/rman01.dbf 20971520
注意, 这里的file id。 我们这里的file id 和 oracle 系统内部的file id 相同。 当然这个id 我们也可以自己指定。 当我们在bbed 里设置file id 时,就是根据这个参数文件中的的设置来的。 最好设置为相同,不然以后可能会混淆。
将上面查询出来的结果保存在一个文本文件中
[oracle@hxy ~]$ vi filelist.txt
1 /opt/oracle/oradata/orcl/system01.dbf 524288000
2 /opt/oracle/oradata/orcl/undotbs01.dbf 209715200
3 /opt/oracle/oradata/orcl/sysaux01.dbf 251658240
4 /opt/oracle/oradata/orcl/user01.dbf 5242880
5 /opt/oracle/oradata/orcl/hxy01.dbf 20971520
6 /opt/oracle/oradata/orcl/hxy101.dbf 20971520
7 /opt/oracle/oradata/orcl/rman01.dbf 20971520
~
(2) 创建parameter file:
[oracle@hxy ~]$ cat bbed.par
blocksize=8192
listfile=/home/oracle/filelist.txt
mode=edit
参数详细下面有说明
说明:
1)bbed.par和filelist.txt的命名可以随意
2)上面的配置都要按照你在建库时的真实情况,如,数据块的大小为8k,则blocksize就要写8k.
4 登入连接:
bbed的密码是blockedit
[oracle@hxy ~]$ bbed parfile=/home/oracle/bbed.par
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Sat Apr 12 13:18:46 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 1
BLOCK# 1
OFFSET 0
DBA 0x00400001 (4194305 1,1)
FILENAME /opt/oracle/oradata/orcl/system01.dbf
BIFILE bifile.bbd
LISTFILE /home/oracle/filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
参数说明:(下面的参数在参数文件中都能设置)
mode 有两个取值,一个是browse,也就是仅仅浏览数据,不做修改。
blocksize
spool =yes|no
cmdfile=文件名
logfile=文件名
parfile =文件名
bifile
revert=yes|no
slient=yes|no
至此完成了BBED的配置和连接!
11g新特性:
OracleDatabase 11g中缺省的未提供BBED库文件,但是可以用10g的文件编译出来,需要先从10g中复制如下文件到相应目录,然后再执行上述连接命令,参考如下步骤:
(1)复制Oracle 10g文件
Copy $ORA10g_HOME/rdbms/lib/ssbbded.o to$ORA11g_HOME/rdbms/lib
Copy $ORA10g_HOME/rdbms/lib/sbbdpt.o to $ORA11g_HOME/rdbms/lib
Copy $ORA10g_HOME/rdbms/mesg/bbedus.msb to $ORA11g_HOME/rdbms/mesg
Copy $ORA10g_HOME/rdbms/mesg/bbedus.msg to $ORA11g_HOME/rdbms/mesg
Copy $ORA10g_HOME/rdbms/mesg/bbedar.msb to $ORA11g_HOME/rdbms/mesg
(2)编译
make -f $ORA11g_HOME/rdbms/lib/ins_rdbms.mkBBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
三,BBED命令说明(整理于it博客-开心问答网)
获取帮助
BBED> help all
SET DBA [ dba | file#, block# ]
SET FILENAME 'filename'
SET FILE file#
SET BLOCK [+/-]block#
SET OFFSET [ [+/-]byte offset | symbol | *symbol ]
SET BLOCKSIZE bytes
SET LIST[FILE] 'filename'
SET WIDTH character_count
SET COUNT bytes_to_display
SET IBASE [ HEX | OCT | DEC ]
SET OBASE [ HEX | OCT | DEC ]
SET MODE [ BROWSE | EDIT ]
SET SPOOL [ Y | N ]
SHOW [ <SET parameter> | ALL ]
INFO
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
</Nuf>:
N - a number which specifies a repeat count.
u - a letter which specifies a unit size:
b - b1, ub1 (byte)
h - b2, ub2 (half-word)
w - b4, ub4(word)
r - Oracle table/index row
f - a letter which specifies a display format:
x - hexadecimal
d - decimal
u - unsigned decimal
o - octal
c - character (native)
n - Oracle number
t - Oracle date
i - Oracle rowid
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
MODIFY[/x|d|u|o|c] numeric/character string
[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
ASSIGN[/x|d|u|o] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ <bbed command> | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
BBED>
下面是几个常用的:
set 设定当前的环境
show 查看当前的环境参数,跟sqlplus的同名命令类似。
dump 列出指定block的内容
find 在指定的block中查找指定的字符串,结果是显示出字符串,及其偏移量--offset,偏移量就是在block中的字节数
modify 修改指定block的指定偏移量的值,可以在线修改。
copy 把一个block的内容copy到另一个block中
verify 检查当前环境是否有坏块
sum 计算block的checksum,modify之后block就被标识为坏块,current checksum与reqired checksum不一致,sum命令可以计算出新的checksum并应用到当前块。
undo 回滚当前的修改操作,如果手误做错了,undo一下就ok了,回到原来的状态。
revert 回滚所有之前的修改操作,意思就是 undo all
3.1 SET 命令
3.1.1 set dba
Setsthe current data block using the standard Oracle DBA (Data Block Address)format. This is entered as file_id, block.
关于DBA 说明,参考:
Oracle rdba和 dba 说明
http://blog.csdn.net/tianlesoftware/article/details/6529346
SQL> select
2 rowid,
3 dbms_rowid.rowid_relative_fno(rowid)rel_fno,
dbms_rowid.rowid_block_number(rowid)blockno,
dbms_rowid.rowid_row_number(rowid) rowno
from t1 where object_id=100;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- --------------------
AAAMxZAABAAAO3SAAA 1 60882 0
AAAMxZAABAAAO3TAAH 1 60883 7
设置file 1,block 60882
BBED> set dba 1,60882
DBA 0x0040edd2(4255186 1,60882)
如果设置成功,会返回该block的RDBA (Relative Data Block Address),rdba就是rowid中的rfile#+block#。括号里面的是DBA值和block 和 file id。 我们验证一下:
SYS@dave2(db2)> variable dbavarchar2(30);
SYS@dave2(db2)> exec :dba :=dbms_utility.make_data_block_address(1,60882);
PL/SQL procedure successfully completed.
SYS@dave2(db2)> print dba
DBA
----------------------------------------------------------
4255186
3.1.2 set filename
Setsthe current file to the one specified. It must be a valid Oracle data file andit must be enclosed in single quotes. If the file is not in the current path itmust also be fully qualified. If successful, bbed will respond showing the filenow being accessed.
BBED> set filename '/u01/app/oracle/oradata/dave2/users01.dbf'
FILENAME /u01/app/oracle/oradata/dave2/users01.dbf
--必须是一个有效的datafile,并且用单引号括起来
3.1.3 set file
Setsthe current file to the number specified. The number specified must be one ofthe file ids supplied in the filelist referenced at startup. If successful,bbed will respond showing the file id now being accessed.
BBED> set file 4
FILE# 4
--注意这里的number,是我们之前配置的filelist里的number。它可以和我们db 里的file id 不一样。 不过最好是配置一样的。
3.1.4 set block
Setsthe current block. The block is relative to the filename or file already set.The absolute block can be specified, or an offset to the current block can bespecified using the plus (+) or (-) symbols. If successful, bbed will respondshowing the current block.
--注意这里的block 是一个相对的位置,我们需要先指定一个file,然后在指定block。 即对应file里的block。可以对当前block的位置进行+和-操作。
BBED> set file 4
FILE# 4
BBED> set block 60882
BBED-00309: out of range block number(60882)
BBED> set file 1
FILE# 1
BBED> set block 60882
BLOCK# 60882
BBED> set bock +10
BBED-00202: invalid parameter (bock)
BBED> set block +10
BLOCK# 60892
BBED> set block -10
BLOCK# 60882
3.1.5 set offset
Setsthe current offset. The offset is relative to the block already set. Theabsolute offset can be specified, or an offset to the current offset can bespecified using the plus (+) or minus (-) symbols. If successful, bbed willrespond showing the current offset.
--偏移量是相对某个block里的偏移量,可以用+和-进行操作
BBED> set offset 20
OFFSET 20
BBED> set offset +2
OFFSET 22
BBED> set offset -2
OFFSET 20
3.1.6 set blocksize
Setsthe blocksize of the current file. The blocksize must match the file selectedor an error will be reported. If successful, bbed will respond showing thecurrent blocksize.
设置当前datafile 的blocksize 大小,该大小必须和datafile 的实际block 匹配,否则会报错。
BBED> set blocksize 8192
BLOCKSIZE 8192
3.1.7 set listfile
Setsthe listfile to the specified file. This option can be used if the listfile wasnot specified on the command line. The listfile must be enclosed in singlequotes. If successful, bbed will respond showing the current listfile.
--在前面讲过,可以通过parameter file 来指定bbed的属性,当然也可以通过set 来指定这些信息。对于listfile的文件,必须用单引号括起来。
BBED> set listfile '/u01/filelist.txt'
LISTFILE /u01/filelist.txt
3.1.8 set width
Setsthe current screen width. If not specified bbed will assume an 80-characterdisplay.
设定当前屏幕的宽度,默认是80.
BBED> set width 200
WIDTH 200
3.1.9 set count
Setsthe number of bytes of the data block to display from the dump command. Thedefault is 512.
Tosee an entire 8Kb block therefore you would need to dump the block eight timesat offsets 0, 512, 1024, 1536, 2048, 2560, 3092 and 3604.
Bysetting the count higher bbed will dump more of the block each time. Byreducing it a smaller dump can be achieved.
设置dump 命令显示bytes的数量。默认是512 bytes。
BBED> set count 512
COUNT 512
3.1.10 set ibase
Setsthe internal number base. The default is decimal. However it can also be set tohexadecimal or octal. This allows the set file, set block and set offsetcommands to use an alternate base to decimal. If successful, bbed will respondshowing the current base:
--设置内部的数字格式,默认是十进制。 也可以设置为十六进制或者八进制。设置完数字格式之后,可是使用该格式来设置blcok,offset等。
BBED> set ibase hex
IBASE Hex
BBED> set block +D
BLOCK# 14
BBED> set ibase decimal
IBASE Dec
3.1.11 set obase
Thepurpose of this command is unknown.
3.1.12 set mode
Setsthe bbed mode. The options are browse or edit. In browse mode no changes can bemade. This is the suggested mode for first-time users, or if you are intendingto use the tool only to inspect data blocks.
--设置bbed 的模式,该默认有2种:browse 和 edit。 browse 模式不允许进行修改。 如果要修改,就选择edit模式。 这个在我们的之前的配置文件里,我们选择了edit。
BBED> set mode browse
MODE Browse
BBED> set mode edit
MODE Edit
3.1.13 set spool
Thiscommand appears to not be implemented.
3.2 show 命令
显示当前的配置选项。
BBED> show
FILE# 1
BLOCK# 14
OFFSET 0
DBA 0x0040000e(4194318 1,14)
--注意这里的block 变成了14. 是我们刚才设置的。
FILENAME /u01/app/oracle/oradata/dave2/system01.dbf
BIFILE bifile.bbd
LISTFILE /u01/filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 200
COUNT 512
LOGFILE log.bbd
SPOOL No
3.3 info
显示当前可以进行browse 或者edit 的file。即我们filelist 里指定的datafile信息。
BBED> info
File# Name Size(blks)
----- ---- ----------
1 /u01/app/oracle/oradata/dave2/system01.dbf 215040
2 /u01/app/oracle/oradata/dave2/undotbs01.dbf 113280
3 /u01/app/oracle/oradata/dave2/sysaux01.dbf 48640
4 /u01/app/oracle/oradata/dave2/users01.dbf 640
5 /u01/app/oracle/oradata/dave2/example01.dbf 12800
6 /u01/app/oracle/oradata/dave2/dave01.dbf 1280
7 /u01/app/oracle/oradata/dave2/undotbs02.dbf 128
8 /u01/app/oracle/oradata/dave2/huaining01.dbf 6400
--一行不能完整显示,设置一下width 参数,就ok了
BBED> set width 65
WIDTH 65
BBED> info
File# Name Size(blks)
----- ---- ----------
1 /u01/app/oracle/oradata/dave2/system01.dbf 215040
2 /u01/app/oracle/oradata/dave2/undotbs01.dbf 113280
3 /u01/app/oracle/oradata/dave2/sysaux01.dbf 48640
4 /u01/app/oracle/oradata/dave2/users01.dbf 640
5 /u01/app/oracle/oradata/dave2/example01.dbf 12800
6 /u01/app/oracle/oradata/dave2/dave01.dbf 1280
7 /u01/app/oracle/oradata/dave2/undotbs02.dbf 128
8 /u01/app/oracle/oradata/dave2/huaining01.db 6400
3.4 Map
Themap command shows a map of the current block. It can be combined with the /voption to produce a more verbose output. The map shows the offsets throughoutthe block where certain information can be found such as the block header, thedata block header or the row directory.
Ifthe set commands have not been used to set a current block, or it the user simplywishes to examine another block while keeping the current block their focus,the file name, file id, block or DBA can be specified with the command.
Map会通过偏移量来显示block里的详细信息,如block header,data block header 和row directory。 使用/v 选项,可以查看更详细的信息。
在不指定block的情况下,会显示当前block的信息&#