Oracle BBED(Oracle Block Browser and Editor)工具是Oracle内部提供的数据块级别查看和修改工具。借助这个工具,我们可以方便的查看到Oracle块block级别的存储细节信息,更好的了解Oracle Internal结构技术细节
首先,要说明BBED是非Oracle推荐使用的工具,只提供给内部进行恢复处理使用,对外是不提供任何资料和相关技术支持。所以,我们如果计划使用该工具,特别是在生产环境下使用,都是我们的最后选择方案。一定要在有备份能恢复的时候进行使用,否则贸然使用BBED,容易造成数据库启动失败或者更严重的问题。
BBED提供的版本中,只有Linux/Unix,在Windows上是没有对应版本的。索引使用BBED的环境通常是命令行方式。而且BBED在Oracle内部是没有提供编译好的现成版本,需要我们手工性编译链接操作。
oracle 10g bbed 安装文档
oracle 10g bbed 安装文档
[oracle@test ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@test lib]$ ls
config.c ins_rdbms.mk ksnnt2.o rfsin.o sskfoded.o
config.o jox.o ktd.o rfsxc.o sskrmed.o
cursize.o joxoff.o kxmnsd.o s0exudrv.o sskrned.o
dbfsize.o kciwcx.o kxmwsd.o s0impdrv.o sskrsed.o
defopt.o kcsm.o kzlnlbac.o s0kudbv.o ssoraed.o
dmndm.o kfod.o libdbtools10.a s0kuzr.o sstrced.o
dmndmse.o kgupc.o libdsga10.a s0kvpf.o strcpt.o
dmwdm.o kgutc.o libknlopt.a s0udexp.o sulmain.o
dumpsga.o kkpoban.o libodm10.a s0udimp.o tg4pwd.o
env_rdbms.mk kkxntp.o libperfsrv10.a sbbdpt.o tstshm.o
genezi.o kkxwtp.o libqsmashr.a shorm.o ttcoerr.o
genksms.o kopc.o libskgxns.a shou.o ttcsoi.o
hoaoci.o kprnts.o libskgxpd.a sjsex.o wpspldrv.o
hoat.o kprwts.o libskgxpu.a skfedpt.o xaondy.o
hoax.o kpucb.o libxdb.a skfodpt.o xaonsl.o
homts.o kpudfo.o mapsga.o skrmpt.o xsnoolap.o
hormc.o kpundf.o maxmem.o skrnpt.o xsyeolap.o
hormd.o ksms.o nmliblist skrspt.o zsmsdrv.o
horm.o ksnkcs.o opimai.o sllfls.o
hormt.o ksnkkpo.o osh.o srfsd.o
hout.o ksnktd.o rfscom.o ssbbded.o
hsxaora.o ksnnni.o rfsd.o sskfeded.o
[oracle@test lib]$ pwd
/opt/app/oracle/product/10g/rdbms/lib
[oracle@test lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
rm -f /opt/app/oracle/product/10g/rdbms/lib/bbed
gcc -o /opt/app/oracle/product/10g/rdbms/lib/bbed -L/opt/app/oracle/product/10g/rdbms/lib/
-L/opt/app/oracle/product/10g/lib/ -L/opt/app/oracle/product/10g/lib/stubs/ -L/usr/lib -
lirc /opt/app/oracle/product/10g/lib/s0main.o
/opt/app/oracle/product/10g/rdbms/lib/ssbbded.o
/opt/app/oracle/product/10g/rdbms/lib/sbbdpt.o `cat
/opt/app/oracle/product/10g/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -
lnnz10 -lnl10 /opt/app/oracle/product/10g/rdbms/lib/defopt.o -ldbtools10 -lclntsh `cat
/opt/app/oracle/product/10g/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -
lnnz10 -lnl10 -lnro10 `cat /opt/app/oracle/product/10g/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/app/oracle/product/10g/lib/ldflags`
-lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat
/opt/app/oracle/product/10g/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/app/oracle/product/10g/lib/sysliblist` -Wl,-
rpath,/opt/app/oracle/product/10g/lib -lm `cat
/opt/app/oracle/product/10g/lib/sysliblist` -ldl -lm -L/opt/app/oracle/product/10g/lib
[oracle@test lib]$
[oracle@test lib]$ cp bbed $ORACLE_HOME/bin
[oracle@test lib]$ ls -l bbed
[oracle@test bin]$ pwd
/opt/app/oracle/product/10g/bin
[oracle@test bin]$ cat file.txt
1 /opt/app/oracle/oradata/wolf/system01.dbf 503316480
2 /opt/app/oracle/oradata/wolf/undotbs01.dbf 26214400
3 /opt/app/oracle/oradata/wolf/sysaux01.dbf 251658240
4 /opt/app/oracle/oradata/wolf/users01.dbf 5242880
5 /opt/app/oracle/oradata/wolf/wolfblock01.dbf 104857600
[oracle@test bin]$ cat bbed.txt
blocksize=8192
listfile=/opt/app/oracle/product/10g/bin/file.txt
mode=edit
[oracle@test bin]$
[oracle@test bin]$ ./bbed parfile=/opt/app/oracle/product/10g/bin/bbed.txt
Password: (这里的密码是:blockedit)
BBED: Release 2.0.0.0.0 - Limited Production on 星期一 7月 16 03:01:57 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
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 [
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 ]
:
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]
BBED> set filename '/opt/app/oracle/oradata/wolf/wolfblock01.dbf'
FILENAME /opt/app/oracle/oradata/wolf/wolfblock01.dbf
BBED>
oracle 11g下的安装
BBED is not available in 11g but you can still link it after getting the following files
from any previous version like 10gR2.
Copy $ORA10g_HOME/rdbms/lib/ssbbded.o to $ORA11g_HOME/rdbms/lib
Copy $ORA10g_HOME/rdbms/lib/sbbdpt.o to $ORA11g_HOME/rdbms/lib
Message files (list may differ):
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
Issue the following command:
make -f $ORA11g_HOME/rdbms/lib/ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed
$ORACLE_HOME/bin/bbed
$ORA11g_HOME/bin/bbed
password: blockedit
实验一
利用bbed恢复(实验如盖总说的不可模仿)
查找377block
SQL> select segment_name,file_id,block_id from dba_extents where block_id=377;
SEGMENT_NAME
--------------------------------------------------------------------------------
FILE_ID BLOCK_ID
---------- ----------
BOOTSTRAP$
1 377
_SYSSMU3$
2 377
I_DIR$INSTANCE_JOB_NAME
3 377
SQL> select * from bootstrap$ where rownum<2;
LINE# OBJ#
---------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
-1 -1
8.0.0.0.0
SQL> update bootstrap$ set sql_text='9.0.0.0.0' where line#=-1;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from bootstrap$ where rownum<2;
LINE# OBJ#
---------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
-1 -1
9.0.0.0.0
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 104859216 bytes
Database Buffers 176160768 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01092: ORACLE instance terminated. Disconnection forced
查看日志
[root@test bdump]# tail -f alert_wolf.log
SMON: enabling cache recovery
Mon Jul 16 03:55:39 2012
Errors in file /opt/app/oracle/admin/wolf/udump/wolf_ora_23472.trc:
ORA-00704: bootstrap process failure
ORA-00702: bootstrap verison '9.0.0.0.0' inconsistent with version '8.0.0.0.0'
Mon Jul 16 03:55:39 2012
Error 704 happened during db open, shutting down database
USER: terminating instance due to error 704
Instance terminated by USER, pid = 23472
ORA-1092 signalled during: ALTER DATABASE OPEN...
这步照着书上改的
BBED> modify /c "8" offset 1276
File: /opt/app/oracle/oradata/wolf/system01.dbf (1)
Block: 378 Offsets: 1276 to 1284 Dba:0x0040017a
------------------------------------------------------------------------
38000000 00000000 00
<32 bytes per line>
BBED> verify
DBVERIFY - Verification starting
FILE = /opt/app/oracle/oradata/wolf/system01.dbf
BLOCK = 378
Block 378 is corrupt
Corrupt block relative dba: 0x0040017a (file 0, block 378)
Bad check value found during verification
Data in bad block:
type: 6 format: 2 rdba: 0x0040017a
last change scn: 0x0000.00087dc5 seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x7dc50601
check value in block header: 0x127f
computed block checksum: 0x138
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 1
Total Blocks Influx : 0
BBED> sum apply
Check value for File 1, Block 378:
current = 0x1347, required = 0x1347
BBED> verify
DBVERIFY - Verification starting
FILE = /opt/app/oracle/oradata/wolf/system01.dbf
BLOCK = 378
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
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 104859216 bytes
Database Buffers 176160768 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> select * from bootstrap$ where rownum
2 <2;
LINE# OBJ#
---------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
-1 -1
8.0.0.0.0
SQL>
实验二
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/opt/app/oracle/oradata/wolf/system01.dbf
/opt/app/oracle/oradata/wolf/undotbs01.dbf
/opt/app/oracle/oradata/wolf/sysaux01.dbf
/opt/app/oracle/oradata/wolf/users01.dbf
/opt/app/oracle/oradata/wolf/wolfblock01.dbf
SQL> select file#,name from v$datafile;
FILE#
----------
NAME
--------------------------------------------------------------------------------
1
/opt/app/oracle/oradata/wolf/system01.dbf
2
/opt/app/oracle/oradata/wolf/undotbs01.dbf
3
/opt/app/oracle/oradata/wolf/sysaux01.dbf
FILE#
----------
NAME
--------------------------------------------------------------------------------
4
/opt/app/oracle/oradata/wolf/users01.dbf
5
/opt/app/oracle/oradata/wolf/wolfblock01.dbf
SQL> drop table wolfblock;
Table dropped.
SQL> create table wolfblock(id number) tablespace wolfblock;
Table created.
SQL> insert into wolfblock values(1);
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> select * from wolfblock;
ID
----------
1
1
1
1
SQL> select rowid,dbms_rowid.rowid_relative_fno(rowid)
rel_fno,dbms_rowid.rowid_block_number(rowid) blockno from wolfblock;
ROWID REL_FNO BLOCKNO
------------------ ---------- ----------
AAAMj+AAFAAAAAXAAA 5 23
AAAMj+AAFAAAAAXAAB 5 23
AAAMj+AAFAAAAAXAAC 5 23
AAAMj+AAFAAAAAXAAD 5 23
SQL> alter system dump datafile 5 block 23;
System altered.
dump 和 bbed
后面的结果研究中
bbed相当很小,但是很复杂,慢慢研究
欢迎加入:
119224876(db china联盟),233065499(db china联盟),229845401(虚拟化-云计算-物联网)