BBED是Oracle 内部使用的命令,所以Oracle 不提供技术支持。 为了安全,BBED设置了口令保护,默认密码为blockedit。
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)
[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
复制生成的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
如下:
(1)先获取datafile 的信息
将datafile 的信息写入一个文件,格式为:文件编号 文件名字 文件大小。可以通过如下SQL 获取:
SYS@orcl>select file#||' '||name||' '||bytes from v$datafile ;将上面查询出来的结果保存在一个文本文件中
[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.
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,也就是仅仅浏览数据,不做修改。 另外一个取值是edit,就是要修改数据。
blocksize 是数据文件的块大小
spool =yes|no 的含义是否要把操作过程写入日志
cmdfile=文件名 启动bbed 后直接执行的脚本
logfile=文件名 日志文件的名字
parfile =文件名 参数文件的名字,里面写很多参数
bifile =文件名 修改数据块前可以将修改前映像保存在一个文件里,以便于问问题后使用bifile的内容进行恢复
revert=yes|no 表示是否可以利用bifile 进行回退
slient=yes|no 表示是否可以使用静默模式,适合使用cmdfile的批处理方式
至此完成了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> 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.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.
显示当前的配置选项。
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
显示当前可以进行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
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的信息,如果想显示其他block的信息,可以使用file name,file id,block 和DBA 来指定要显示的block。
BBED> map
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 60882 Dba:0x0040edd2
------------------------------------------------------------
KTBData Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @92
struct kdbt[2], 8 bytes @106
sb2kdbr[4] @114
ub1freespace[7974] @122
ub1rowdata[92] @8096
ub4tailchk @8188
--这个是默认情况,@后面代表的对应的信息在block里的偏移量,即offset。
--通过dba 来指定某个block
BBED> map /v dba 1,60882
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 60882 Dba:0x0040edd2
------------------------------------------------------------
KTBData 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 @92
ub1 kdbhflag @92
b1 kdbhntab @93
b2 kdbhnrow @94
sb2 kdbhfrre @96
sb2 kdbhfsbo @98
sb2 kdbhfseo @100
b2 kdbhavsp @102
b2 kdbhtosp @104
struct kdbt[2], 8 bytes @106
b2 kdbtoffs @106
b2 kdbtnrow @108
sb2kdbr[4] @114
ub1freespace[7974] @122
ub1rowdata[92] @8096
ub4tailchk @8188
--通过block 来map
BBED> map block 60888
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 60888 Dba:0x0040edd8
------------------------------------------------------------
KTBData Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @92
struct kdbt[2], 8 bytes @106
sb2kdbr[4] @114
ub1freespace[7936] @122
ub1rowdata[130] @8058
ub4tailchk @8188
Map 显示的具体信息解释如下:
struct kcbh, 20 bytes |
Block Header Structure |
ub1 type_kcbh |
Block type (see Header Block Types below) |
ub1 frmt_kcbh |
Block format 1=Oracle 7, 2=Oracle 8+ |
ub1 spare1_kcbh |
Not used |
ub1 spare2_kcbh |
Not used |
ub4 rdba_kcbh |
RDBA -Relative Data Block Address |
ub4 bas_kcbh |
SCN Base |
ub2 wrp_kcbh |
SCN Wrap |
ub1 seq_kcbh |
Sequence number, incremented for every change made to the block at the same SCN |
ub1 flg_kcbh |
Flag: 0x01 New Block 0x02 Delayed Logging Change advanced SCN/seq 0x04 Check value saved - block XOR‘s to zero 0x08 Temporary block |
ub2 chkval_kcbh |
Optional block checksum (if DB_BLOCK_CHECKSUM=TRUE) |
ub2 spare3_kcbh |
Not used |
struct ktbbh, 72 bytes |
Transaction Fixed Header Structure |
ub1 ktbbhtyp |
Block type (1=DATA, 2=INDEX) |
union ktbbhsid, 4 bytes |
Segment/Object ID |
struct ktbbhcsc, 8 bytes |
SCN at last block cleanout |
b2 ktbbhict |
Number of ITL slots |
ub1 ktbbhflg |
0=on the freelist |
ub1 ktbbhfsl |
ITL TX freelist slot |
ub4 ktbbhfnx |
DBA of next block on the freelist |
struct ktbbhitl[2], 48 bytes |
ITL list index |
struct kdbh, 14 bytes |
Data Header Structure |
ub1 kdbhflag |
N=pctfree hit(clusters); F=do not put on freelist; K=flushable cluster keys |
b1 kdbhntab |
Number of tables (>1 in clusters) |
b2 kdbhnrow |
Number of rows |
sb2 kdbhfrre |
First free row entry index; -1 = you have to add one |
sb2 kdbhfsbo |
Freespace begin offset |
sb2 kdbhfseo |
Freespace end offset |
b2 kdbhavsp |
Available space in the block |
b2 kdbhtosp |
Total available space when all TXs commit |
struct kdbt[1], 4 bytes |
Table Directory Entry Structure |
b2 kdbtoffs |
|
b2 kdbtnrow |
|
sb2 kdbr[1] |
Row Directory |
ub1 freespace[8030] |
Free Space |
ub1 rowdata[38] |
Row Data |
ub4 tailchk |
(See Tailchecks below) |
Differentblock types are designated by the first byte of the block. The following tableshows how to decode the block type:
不同的block 可以第一个byte的值是不一样的。 具体值对应block 类型如下。
Header Block Types
ID |
Type |
01 |
Undo segment header |
02 |
Undo data block |
03 |
Save undo header |
04 |
Save undo data block |
05 |
Data segment header (temp, index, data and so on) |
06 |
KTB managed data block (with ITL) |
07 |
Temp table data block (no ITL) |
08 |
Sort Key |
09 |
Sort Run |
10 |
Segment free list block |
11 |
Data file header |
可以通过dump block来查看对应的具体的值。 下文讲dump时会有相关的示例。
oracleblocks 的最后4个bytes 是tail check。 下面看一下oracle 9i block的tail check 组成。
Tailchecks
Thetail of an Oracle 8+ block is a concatenation of the lower order two bytes ofthe SCN base, the block type and the SCN sequence number.
Oracleblock tail 由4个bytes组成,但实际上只用了低2个bytes来存放。 2个bytes的tail 由scn base,block type 和 scn sequence 组成。
E.g, if the SCN base number is 0x00029728,the block type is 06 and the SCN sequence number is 0x02, the tail check wouldbe 0x97280602:
SCN base Type SCN seq
9728 06 02
Althoughthis tail check value is generated from three components, Oracle treats thefinal value as a single unsigned integer stored as a word (4-bytes). Onlittle-endian architecture machines, which include Intel, the value will bestores as low-order byte first.
虽然tail check 由3个部分组成,但是oracle 把这3部分作为一个整体来存储,并且占用4个bytes。
对于little-endian(低端)架构的机器,包括Intel, 他们会先存放low-order byte,即低位字节。
Thereforeif the tail check is examined in the block using a standard block editor, orthe dump command which will be explained in the next section, the byte ordermay look different. A tail check of 0x97280602 stored on an Intel machine wouldbe written to disk as "02062897".
可以通过标准block editor 或者dump 来查看tail check。 对于不同的机器,他们存储的顺序是不一样的。比如tail check 0x97280602 在Intel Machine 就被存储为02062897,因为它会先保存low-order bytes。
Thedump command dumps the content of the block to the screen. It can be combinedwith the /v option to produce a more verbose output. TheDBA, Filename, File, Block and/or Offset to dump can be specified with thecommand. If these are not specified the current file, block and offsetas established with the set command will be dumped. The size of the dump islimited by the set count option and defaults to 512 bytes or alternatively thesize of the dump can be specified with the command.
dump命令可以讲block 的内从显示到屏幕。 每次显示的bytes由count 控制,默认是512 bytes。 使用 /v 选项,可以显示更多详细信息。
示例:
BBED> dump /vdba 1,60884 offset 0 count 128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 60884 Offsets: 0 to 127 Dba:0x0040edd4
-------------------------------------------------------
06a20000 d4ed4000 e3580900 00000106 l.¢..Ôí@.ãX......
64610000 01000000 fb000000 de580900 lda......û...ÞX..
00000000 02000200 00000000 01002900 l..............).
15010000 a3008000 ce002700 00800000 l....£...Î.'.....
de580900 01002800 15010000 a4008000 lÞX....(.....¤...
ce003500 06200000 e3580900 01020700 l Î.5....ãX......
ffff2400 021fde1e de1e0000 01000100 l..$...Þ.Þ.......
0600851f 6f1f591f 441f2e1f 181f021f l....o.Y.D.......
<16 bytes per line>
我们看一下blockheader 中第一行16个bytes 的架构:
Type |
Format |
Unused |
RDBA |
SCN Base |
SCN Wrap |
Seq |
Flag |
06 |
a2 |
0000 |
d4ed4000 |
e3580900 |
0000 |
01 |
06 |
在上一节讲到不同的blocktype id 代表不同的类型:
06 |
KTB managed data block (with ITL) |
我们在dump 一个看看:
BBED> dump /v dba 1,6081 offset 0 count128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 6081 Offsets: 0 to 127 Dba:0x004017c1
-------------------------------------------------------
10a20000 c1174000 972a0000 00000104 l.¢..Á.@..*......
cbf20000 00000000 00000000 00000000 lËò..............
00000000 01000000 07000000 20100000 l............ ...
00000000 01000000 07000000 c3174000 l............Ã.@.
00000000 00000000 00000000 01000000 l................
00000000 00000000 00000000 01000000 l ................
00000000 7e030000 00000040 c2174000 l....~......@Â.@.
07000000 00000000 00000000 00000000 l................
这个block headertype 就变成了10.
Theprint command allows data structures to be printed in raw or formatted output.The DBA, Filename, File, Block and/or Offset to print can be specified with thecommand. If these are not specified the current file, block and offset asestablished with the set command will be printed.
print命令输出datastructures。 在使用print时,可以指定dba,block 等参数来限定输出特定block。
Ifthe print command is issued with just the block and offset to print, bbed willdisplay the data structure at that offset.
在3.4 节map里讲了block的结构,在前面,我们讲过,可以通过dump 来查看block 的type。通过print 也可以查看。现在我们print 一个file 1,block 60811的Data Block Header 的type。
BBED> set dba 1,60811
DBA 0x0040ed8b(4255115 1,60811)
BBED> set offset 0
OFFSET 0
BBED> p kcbh.type_kcbh
ub1 type_kcbh @0 0x06
--type 类型为06.
Itis also possible to use the print command to print individual data structuresby specifying the name.
可以通过print 输出指定名称的block structures。
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 0x0040ed8b
ub4 bas_kcbh @8 0x00095560
ub2 wrp_kcbh @12 0x0000
ub1 seq_kcbh @14 0x01
ub1 flg_kcbh @15 0x06 (KCBHFDLC,KCBHFCKV)
ub2 chkval_kcbh @16 0x4667
ub2 spare3_kcbh @18 0x0000
Ifwe wanted to determine the number of rows in the block, we could print the dataheader structure or kdbh:
如果我们想确定block 中row的数量,可以print data header structure 或者kdbh。
struct kdbh, 14 bytes |
Data Header Structure |
BBED> p kdbh
struct kdbh, 14 bytes @92
ub1 kdbhflag @92 0x01 (KDBHFFK)
b1kdbhntab @93 2
b2kdbhnrow @94 10
sb2 kdbhfrre @96 -1
sb2 kdbhfsbo @98 42
sb2 kdbhfseo @100 7917
b2kdbhavsp @102 7875
b2kdbhtosp @104 7875
We can also specifying certain datastructure elements to print such as the row count:
也可以指定某个具体的structure元素进行print。
BBED> p kdbhnrow
b2 kdbhnrow @94 10
该block里保存了10行rows。
注意:
当print 一个data structure 时,输出的格式如下:
UnitSize* | Name | Offset| Value
*Unit size is shown in bytes and indicates if the value is signed (s) orunsigned (u).
Inaddition to printing information about the specified data structure, the printcommand can also be used to print information about thelocation the data structure points to by using the pointer (*) prefix.
--在pointer 加前缀* 可以print location data structure。
For example we can display the block row information by printing the kdbr datastructure,kdbr 里保存的是row directory 的信息。
sb2 kdbr[1] |
Row Directory |
BBED> p kdbr
sb2 kdbr[0] @114 8070
sb2 kdbr[1] @116 8053
sb2 kdbr[2] @118 8036
sb2 kdbr[3] @120 8019
sb2 kdbr[4] @122 8002
sb2 kdbr[5] @124 7985
sb2 kdbr[6] @126 7968
sb2 kdbr[7] @128 7951
sb2 kdbr[8] @130 7934
sb2 kdbr[9] @132 7917
格式的对应关系:
Unit Size* | Name | Offset | Value
sb2 kdbr[9] @132 7917
从上面的结果,可以看出,在这个数据块里有10行记录。 每行的pointer 需要2个bytes来存储。 这10行row的offset 从114 到132.
我们可以使用kdbr[0] 作为一个指针来print 它对应的内容。这个kdbr[0] 是一个本地的data structure,我们print 需要加*号前缀。
BBED> p *kdbr[0]
rowdata[153]
------------
ub1 rowdata[153] @8162 0xac
通过这个信息,我们可以知道该行记录的偏移量是8162. 我们就dump 它的具体信息。
BBED> d /v dba 1,60811 offset 8162 count128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 60811 Offsets: 8162 to 8191 Dba:0x0040ed8b
-------------------------------------------------------
ac000209 00090000 40ed8b00 000040ed l¬.......@í....@í
8b000003 c2052702 c1020106 6055 l ....Â.'.Á...`U
<16 bytes per line>
Theprint command can also print absolute offsets, although it does not offer thecount option like the dump command:
print命令也可以直接输出一个绝对的offset内容。
BBED> p offset 8162
rowdata[153]
------------
ub1 rowdata[153] @8162 0xac
这个输出结果默认是16进制的。我们可以将其修改成其他格式。
Switch |
Display Format |
/x |
Hex |
/d |
signed decimal |
/u |
unsigned decimal |
/o |
Octal |
/c |
Character |
/n |
Oracle Number |
/t |
Oracle Date |
/i |
Oracle ROWID |
BBED> p offset 8162
rowdata[153]
------------
ub1 rowdata[153] @8162 0xac
BBED> p /d offset 8162
rowdata[153]
------------
ub1 rowdata[153] @8162 172
Theexamine command is used to display data from the block in raw or formattedoutput. The DBA, Filename, File, Block and/or Offset to examine can bespecified with the command. If these are not specified the current file, blockand offset as established with the set command will be examined. If the examinecommand is issued with just the block and offset to examine, bbed will displaythe data structure at that offset.
--examine命令也是用来显示datablock的内容的。
Unlikethe print command it cannot interpret data structures, but it can be used todisplay row information. Combined with knowledge of the data type of the row,it can be used to retrieve complete rows from the block:
--print命令不能对datastructures 进行一个解释说明。
Theexamine command will interpret the data in the block according to the followingswitches:
Switch |
Display Format |
/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 |
Theexamine command allows switches from the print command to be combined withthese specific switches to interpret data.
--examine可以根据switch的方式和print 命令进行一个结合来对data 进行解释说明。
Forexample if we wanted to interpret data as an Oracle table row with the firstcolumn character and the second and third columns numeric, we would execute thecommand as follows:
BBED>x /rcnn
Thefollowing example shows the print and examine commands being used to step throughthe first and second rows of a block, with the data interpreted as a row in theformat: character, number, number:
BBED> set dba 1,60811
DBA 0x0040ed8b(4255115 1,60811)
BBED> p *kdbr[0]
rowdata[153]
------------
ub1 rowdata[153] @8162 0xac
BBED> x /rcnn
rowdata[153] @8162
------------
flag@8162: 0xac (KDRHFL, KDRHFF, KDRHFH,KDRHFK)
lock@8163: 0x00
cols@8164: 2
kref@8165: 9
mref@8167: 9
hrid@8169:0x0040ed8b.0
nrid@8175:0x0040ed8b.0
col 0[3] @8181: Â.'
col 1[2] @8185: 1
BBED> p *kdbr[1]
rowdata[136]
------------
ub1 rowdata[136] @8145 0x6c
BBED> x /rcnn
rowdata[136] @8145
------------
flag@8145: 0x6c (KDRHFL, KDRHFF, KDRHFH,KDRHFC)
lock@8146: 0x02
cols@8147: 4
col 0[2] @8149: Á.
col 1[1] @8152: 0
col 2[2] @8154: 3
col 3[4] @8157: 42092
Arepeat count can also be specified to repeat the examine command for subsequentrows. The following shows the print command being used to position the offsetat the last row and then the next three rows are examined.
examine命令也可以指定多行进行显示。 下面的示例我们通过print命令讲offset 指向到最后一个位置。 然后repeat 3次。
BBED> p kdbhnrow
b2 kdbhnrow @94 10
--这个block上总共有10 个rows。
BBED> p *kdbr[9]
rowdata[0]
----------
ub1 rowdata[0] @8009 0x6c
--用print 将位置指向最后一个row。
BBED> x /3rcnn
rowdata[0] @8009
----------
flag@8009: 0x6c (KDRHFL, KDRHFF, KDRHFH,KDRHFC)
lock@8010: 0x02
cols@8011: 4
col 0[2] @8013: Á.
col 1[1] @8016: 0
col 2[2] @8018: 27
col 3[4] @8021: 52385
rowdata[17] @8026
-----------
flag@8026: 0x6c (KDRHFL, KDRHFF, KDRHFH,KDRHFC)
lock@8027: 0x02
cols@8028: 4
col 0[2] @8030: Á.
col 1[1] @8033: 0
col 2[2] @8035: 24
col 3[4] @8038: 42280
rowdata[34] @8043
-----------
flag@8043: 0x6c (KDRHFL, KDRHFF, KDRHFH,KDRHFC)
lock@8044: 0x02
cols@8045: 4
col 0[2] @8047: Á.
col 1[1] @8050: 0
col 2[2] @8052: 21
col 3[4] @8055: 42224
--examine 显示3次。
注意:
Notethat Oracle fills data blocks from the bottom-up, so setting the offset to thefirst row will prohibit the use of the repeat option.
Oracle使用block 是从底向上的。 如果讲offset 设置为0. 那么将会组织repeat 的操作。
假如当前current row 是3,repeat 2次,那么row 3 和row 2 将被显示。 如果current row 是9, repeat 3次,那么row 9,row 8 和row 7 将被显示。
如果不能满足repeat,就会返回错误。
Thefind command is used to locate data within a block. The command allows hex,string or numeric data to be searched for. The pattern can be searched for fromthe top of the block (offset 0) using the TOP directive, or from the currentposition using the CURR directive.
find命令可以用来搜索关键字。 可以从offset 0 搜索到top 或者从当前的offset 搜索到top。
Switchesare used to determine the data type of the pattern to search for. These areshown below:
Switch |
Datatype |
/x |
Hexadecimal |
/d |
Decimal |
/u |
unsigned decimal |
/o |
Octal |
/c |
character (native) |
Note: Number and Dates are not supported bythe find command.
find 命令支持的switch 类型如上表,注意,find 不支持number和Date 。
示例:
--创建表并insert数据
SYS@dave2(db2)> create table dvd(jobvarchar2(100));
Table created.
SYS@dave2(db2)> insert into dvdvalues('Dave is DBA!');
1 row created.
SYS@dave2(db2)> commit;
Commit complete.
SYS@dave2(db2)> insert into dvdvalues('Dave like Oracle!');
1 row created.
SYS@dave2(db2)> commit;
Commit complete.
--查看block 情况:
SYS@dave2(db2)> 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 dvd;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- --------------------
AAAN9VAABAAAcKiAAA 1 115362 0
AAAN9VAABAAAcKiAAB 1 115362 1
--设置block 和 offset
BBED> set file 1
FILE# 1
BBED> set block 115362
BLOCK# 115362
BBED> set offset 0
OFFSET 0
--查找Dave
BBED> find /c Dave top
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
------------------------------------------------------------------------
44617665 206c696b 65204f72 61636c65 212c01010c446176 65206973 20444241
21020616 b3
<32 bytes per line>
bbed 显示在offset 8155的为位置,我们dump 该offset 看看
BBED> d /v dba1,115362 offset 8155 count 128
File: /u01/app/oracle/oradata/dave2/system01.dbf(1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
-------------------------------------------------------
44617665 206c696b 65204f72 61636c65 l Dave like Oracle
212c0101 0c446176 65206973 20444241 l!,...Dave is DBA
21020616 b3 l !...³
<16 bytes per line>
--结果显示的头四个字母就是Dave
如果我们要继续搜索Dave,那么只需要按下f 就可以了,不需要跟参数。
BBED> f
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8176 to 8191 Dba:0x0041c2a2
------------------------------------------------------------------------
44617665 20697320 44424121 020616b3
<32 bytes per line>
BBED> d /v dba1,115362 offset 8176 count 128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8176 to 8191 Dba:0x0041c2a2
-------------------------------------------------------
44617665 20697320 44424121 020616b3 l Dave is DBA!...³
<16 bytes per line>
Thecopy command is used to copy blocks from one location to another. As with othercommands, the file or filename and offset can be specified, or the DBA can bespecified instead.
命令格式如下:
BBED> copy dba 1,115362 to dba 1,115363
copy 是个危险的命令,慎用。
The modify command is used to change data inside a block. The DBA, Filename, File,Block and/or Offset to modify can be specified with the command. If these arenot specified the current file, block and offset as established with the setcommand will be modified. Alternatively a symbol or symbol pointer can bespecified for modification.
The pattern of bytes used to overwrite the original can be specified inhexadecimal, decimal, unsigned decimal, octal or character data using the sameswitches as the find command.
在file 1,block 115362 有我们的Dave,我们这里把Dave 改成dmm。
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 !...³
<16 bytes per line>
--注意,这里只修改了Dave的前三个字母,即把Dave变成了dmme。
注意一点,这里仅仅是修改,还没有进行update,即sum apply, select 才会改变。
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
Dave like Oracle!
Theassign command does symbolic assignment, with type and range checking. Eithertarget or source can be omitted for the current offset.
Forexample, the following command assigns structure at current offset to file 4,block 2 ”s first ITL entry
BBED> assign dba 4, 2 ktbbhitl[0]
Thesum command is used to check and set the block checksum. The DBA, Filename,File, Block and/or Offset to check can be specified with the command. If theseare not specified the current file, block and offset as established with theset command will be checked.
Theapply directive can be used to update the checksum.
我们可以使用bbed 对block 进行修改。 要使这些修改生效,就要使用sum命令。
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
正常情况下,apply 以后,就已改生效了,但是我测试的时候apply 并没有生效,而是把db 重启之后,modify 才生效。
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
Dave like Oracle!
SYS@dave2(db2)> startup force
ORACLE instance started.
Total System Global Area 239075328 bytes
Fixed Size 1218724 bytes
Variable Size 83887964 bytes
Database Buffers 150994944 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
dmme like Oracle!
Thepush and pop commands are used to push a file, block and offset location onto amemory backed stack and then pop them back. This allows a current locationbeing edited to be temporarily saved while another location is examined ormodified.
Note that the stack only stores the locationœ it does notsave the contents.
--push命令将对象放到内存的stack,pop 将对象从内存写回磁盘。
Thefollowing example shows file 7, block 16, offset 8163 being examined. Thelocation is saved with the push command. We then move to file 6, block 1 beforereturning to DBA 7,16 with the pop command.
BBED> push dba 7,16
DBA 0x01c00010 (29360144 7,16)
OFFSET 8163
BBED> set dba 6,1
DBA 0x01800001 (25165825 6,1)
BBED> pop
DBA 0x01c00010 (29360144 7,16)
OFFSET 8163
Thecommand pop all can be used to remove all push‘d entries from the stack. Thecommand show all can be used to show all saved locations.
Therevert command is used to restore a file, filename, block or DBA to it‘soriginal state when bbed was started.
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
这个block是我们之前修改成dmme 的。 我们应用之后,再次select:
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
dmme like Oracle!
还是没有改变,flush 一下buffer cache之后就更改回来了。我们刚才在之前的测试时,是重启了DB。 看来也是启了flush buffer cache的作用。
SYS@dave2(db2)> alter system flushbuffer_cache;
System altered.
SYS@dave2(db2)> select * from dvd;
JOB
--------------------------------------------------------------------------------
Dave is DBA!
Dave like Oracle!
Theundo command rolls back the last modify or assign command. If the undo commandis issued again the modification is re-done.
undo命令是回滚最后一次的操作。
BBED> modify /cdmm 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>
BBED> d /v dba1,115362 offset 8155 count 128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
-------------------------------------------------------
646d6d65 206c696b 65204f72 61636c65 l dmmelike Oracle
212c0101 0c446176 65206973 20444241 l!,...Dave is DBA
21020616 b3 l !...³
<16 bytes per line>
BBED> undo
BBED>modify /x446176 filename '/u01/app/oracle/oradata/dave2/system01.dbf' block115362. offset 8155.
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
------------------------------------------------------------------------
44617665 206c696b 65204f72 61636c65 212c01010c446176 65206973 20444241
21020616 b3
<32 bytes per line>
--undo 下面的modify是oracle 自己执行的。
BBED> d /v dba 1,115362 offset 8155count 128
File:/u01/app/oracle/oradata/dave2/system01.dbf (1)
Block: 115362 Offsets: 8155 to 8191 Dba:0x0041c2a2
-------------------------------------------------------
44617665 206c696b 65204f72 61636c65 l Davelike Oracle
212c0101 0c446176 65206973 20444241 l!,...Dave is DBA
21020616 b3 l !...³
<16 bytes per line>
Theverify command is used to verify the integrity of the block. It performs asimilar function to the dbverify utility.
verify命令用来验证block的完整性。
BBED> verify dba 6,15
DBVERIFY - Verification starting
FILE = /u01/app/oracle/oradata/dave2/dave01.dbf
BLOCK = 15
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
Thecorrupt command is used to mark blocks as media corrupt.
corrupt命令将一个block 标记为corrupt,这样db 在操作时就会跳过该block,从而避免错误。
BBED> corrupt dba 6,15
Block marked media corrupt
Note: The undo command does not undo acorruption. The revert command however does.
注意: undo 命令不能undo 一个corruption,但是revert 命令却可以。
创建测试用户
SYS@orcl>create user hxy identified by oracle default tablespace users temporary tablespace temp;
User created.
创建测试表
SYS@orcl>create table bbed tablespace users as select * from dba_tables;
Table created.
SYS@orcl>select count(*) from bbed;
COUNT(*)
----------
1567
查询BBED所在的数据块号:
SYS@orcl> col segment for a10
SYS@orcl> select segment_name,file_id,block_id from dba_extents where segment_name='BBED';
SEGMENT_NAME FILE_ID BLOCK_ID
--------------------------------------------------------------------------------- ---------- ----------
BBED 4 65
BBED 4 73
BBED 4 81
BBED 4 89
BBED 4 97
BBED 4 105
BBED 4 113
7 rows selected.
连接BBED
[oracle@hxy ~]$ bbed parfile=/home/oracle/bbed.par
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Sat Apr 12 14:25:07 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> set file 4
FILE# 4
BBED> show
FILE# 4
BLOCK# 1
OFFSET 0
DBA 0x01000001 (16777217 4,1)
FILENAME /opt/oracle/oradata/orcl/user01.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
如果在操作中发生了误操作,可以使用revert回滚误操作
BBED> modify /x 0x01000001
File: /opt/oracle/oradata/orcl/user01.dbf (4)
Block: 1 Offsets: 0 to 511 Dba:0x01000001
------------------------------------------------------------------------
01000001 01000001 00000000 00000104 03a40000 00000000 0001200a 2aa8a44f
4f52434c 00000000 52070000 80020000 00200000 04000300 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 63200000 00000000 245d2f30 14185832 33480c00 00000000 00000000
00000000 00000000 00000400 85000000 4f1c5832 84000000 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 04000000 05005553 45525300 00000000 00000000
00000000 00000000 00000000 00000000 04000000 00000000 00000000 4b1a5832
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
d18e5632 6e140c00 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 b65b0c00 0000cbb6 f9f75832 0100950e 02000000 9a780000 10000000
<32 bytes per line>
BBED> revert
All changes made in this session will be rolled back. Proceed? (Y/N) Y
Reverted file '/opt/oracle/oradata/orcl/user01.dbf', block 1
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
改写数据库,模拟坏块
BBED> modify 1000 file 4 block73
File: /opt/oracle/oradata/orcl/user01.dbf (4)
Block: 73 Offsets: 0 to 511 Dba:0x01000049
------------------------------------------------------------------------
03e80000 49000001 036e0c00 00000104 8d0a0000 01000000 76c90000 fe6d0c00
00000000 03003201 41000001 ffff0000 00000000 00000000 00000000 00800000
fe6d0c00 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00012100
ffff5400 2304cf03 cf030000 2100ae1e e01d0c1d 411c711b a11ad719 09193b18
69179716 c315ef14 1b144713 75129d11 c810f10f 1d0f440e 6b0d940c b70bdd0a
050a3209 5a088407 af06da05 fd042304 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>
检查数据块损坏
使用verify命令,可以发现刚才修改的file 4 block 63已经被标记为损坏。
BBED> verify
DBVERIFY - Verification starting
FILE = /opt/oracle/oradata/orcl/user01.dbf
BLOCK = 73
Block 73 is corrupt
Corrupt block relative dba: 0x01000049 (file 0, block 73)
Bad header found during verification
Data in bad block:
type: 3 format: 0 rdba: 0x01000049
last change scn: 0x0000.000c6e03 seq: 0x1 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x6e030601
check value in block header: 0xa8d
computed block checksum: 0x4a05
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> quit
使用DBV检查(DBV工具的目的是为了检查数据文件的物理结构,包括数据文件是否损坏,是否存在逻辑坏块,以及数据文件中包含何种类型的数据)
SYS@orcl>select t1.name,t2.name from v$datafile t1,v$tablespace t2 where t1.ts#=t2.ts#;
NAME NAME
-------------------------------------------------- --------------------------------------------------
/opt/oracle/oradata/orcl/system01.dbf SYSTEM
/opt/oracle/oradata/orcl/undotbs01.dbf UNDOTBS1
/opt/oracle/oradata/orcl/sysaux01.dbf SYSAUX
/opt/oracle/oradata/orcl/user01.dbf USERS
/opt/oracle/oradata/orcl/hxy01.dbf HXY
/opt/oracle/oradata/orcl/hxy101.dbf HXY1
/opt/oracle/oradata/orcl/rman01.dbf RMAN
[oracle@hxy ~]$ dbv file=/opt/oracle/oradata/orcl/user01.dbf
DBVERIFY: Release 10.2.0.1.0 - Production on Sat Apr 12 14:55:23 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /opt/oracle/oradata/orcl/user01.dbf
Page 73 is marked corrupt
Corrupt block relative dba: 0x0100003f (file 4, block 73)
Bad header found during dbv:
Data in bad block:
type: 4 format: 0 rdba: 0x0100003f
last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x00000001
check value in block header: 0xa63f
computed block checksum: 0x1204
Page 65 is marked corrupt
Corrupt block relative dba: 0x01000041 (file 4, block 65)
Bad header found during dbv:
Data in bad block:
type: 3 format: 0 rdba: 0x01000041
last change scn: 0x0000.000c6e0c seq: 0x3 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x6e0c2003
check value in block header: 0x4f5d
computed block checksum: 0x4a23
DBVERIFY - Verification complete
Total Pages Examined : 640
Total Pages Processed (Data) : 63
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 2
Total Pages Failing (Index): 0
Total Pages Processed (Other): 34
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 539
Total Pages Marked Corrupt : 2
Total Pages Influx : 0
Highest block SCN : 814606 (0.814606)
也可以用rman验证
RMAN> backup validate datafile 4;
Starting backup at 12-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/opt/oracle/oradata/orcl/user01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 12-APR-14
然后进入sqlplus查看
SYS@orcl>select * from v$database_block_corruption where file#=4;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
4 63 1 0 CORRUPT
4 65 1 0 CORRUPT
4 73 1 0 CORRUPT
全表扫描时出现ORA-01578的错误
重新启动数据库,执行全表扫描,此时出现错误
SYS@orcl>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@orcl>startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 62916852 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SYS@orcl>select count(*) from bbed;
select count(*) from bbed
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 73)
ORA-01110: data file 4: '/opt/oracle/oradata/orcl/user01.dbf'
数据块损坏,需要恢复。
在这种情况下,如果有备份,需要从备份中恢复;如果没有备份,那么坏块部分的数据库就要丢失了。检查损坏的对象:
SYS@orcl>select tablespace_name,segment_type,owner,segment_name from dba_extents
2 where file_id=4 and block_id between 73 and 90;
TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME
------------------------------ ------------------ ------------------------------ ---------------------------------------------------------------------------------
USERS TABLE SYS BBED
USERS TABLE SYS BBED
USERS TABLE SYS BBED
由上面的查询可知,损坏的块为数据
如果损失的是数据,可以设置内部事件,使得全表扫描跳过那些损坏的block
使用rman进行修复
RMAN> blockrecover
2> datafile 2
3> block 73
4> from
5> backupset
6> ;
Starting blockrecover at 12-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=143 devtype=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished blockrecover at 12-APR-14
RMAN> exit
Recovery Manager complete.
[oracle@hxy orcl]$ rlwrap sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Apr 12 15:29:13 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@orcl>select count(*) from bbed;
COUNT(*)
----------
1534
这里1567-1534=33行数据丢失
下面的方法验证不成功!以后研究吧
如果损失的是数据,可以设置内部事件,使得全表扫描跳过那些损坏的block
SQL> alter system set events='10231 trace name context forever,level 10';
System altered.
统计表中的数据
SQL> select count(*) from bbed;
COUNT(*)
----------
1544
在本次实验中丢失的数据库:1577-1544=33行数据
9.将该用户下的数据导出,删除后,再重建该表,并去取消10231事件
导出数据:
[oracle@test001 test]$ exp alone/alone file=alone.dmp
Export: Release 10.2.0.1.0 - Production on Fri Sep 2 00:30:34 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
在rman中有隐藏的命令clear,可以标记数据块为corrupt,从而实现数据库坏块试验,本篇blog通过dbv,bbed,table select来验证坏块的出现和修复
创建测试表
SQL>
create
table
t_xifenfei
as
2
select
object_id,object_name
from
dba_objects
where
rownum<10;
Table
created.
SQL>
select
rowid,
2 dbms_rowid.rowid_relative_fno(rowid) rel_fno,
3 dbms_rowid.rowid_block_number(rowid) block
4
from
chf.t_xifenfei;
ROWID REL_FNO BLOCK
------------------ ---------- ----------
AAAStAAAEAAAACrAAA 4 171
AAAStAAAEAAAACrAAB 4 171
AAAStAAAEAAAACrAAC 4 171
AAAStAAAEAAAACrAAD 4 171
AAAStAAAEAAAACrAAE 4 171
AAAStAAAEAAAACrAAF 4 171
AAAStAAAEAAAACrAAG 4 171
AAAStAAAEAAAACrAAH 4 171
AAAStAAAEAAAACrAAI 4 171
9
rows
selected.
SQL>
alter
system
checkpoint
;
System altered.
|
dbv验证坏块
[oracle@xifenfei ~]$ dbv
file
=
/u01/oracle/oradata/ora11g/users01
.dbf
DBVERIFY: Release 11.2.0.3.0 - Production on Sun Jan 20 09:12:16 2013
Copyright (c) 1982, 2011, Oracle and
/or
its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE =
/u01/oracle/oradata/ora11g/users01
.dbf
DBVERIFY - Verification complete
Total Pages Examined : 7680
Total Pages Processed (Data) : 3776
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 167
Total Pages Failing (Index): 0
Total Pages Processed (Other): 744
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 2993
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 1006717955 (2956.1006717955)
|
这里创建了t_xifenfei表,数据存储在file 4 block 171中,现在该block一切正常,本试验就是要通过rman来使得该block corrupt,然后通过bbed来修复
bbed查看kcbh
BBED>
set
block 171
BLOCK
# 171
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 0x010000ab
ub4 bas_kcbh @8 0x3c014bfe
ub2 wrp_kcbh @12 0x0b8c
ub1 seq_kcbh @14 0x02
ub1 flg_kcbh @15 0x04 (KCBHFCKV)
ub2 chkval_kcbh @16 0x6e0c <--重点关注
ub2 spare3_kcbh @18 0x0000
|
rman标记坏块
RMAN> BLOCKRECOVER DATAFILE 4 block 171
clear
;
Starting recover at 20-JAN-13
using target database control
file
instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device
type
=DISK
Finished recover at 20-JAN-13
|
dbv再次检查坏块
[oracle@xifenfei ~]$ dbv
file
=
/u01/oracle/oradata/ora11g/users01
.dbf
DBVERIFY: Release 11.2.0.3.0 - Production on Sun Jan 20 09:53:16 2013
Copyright (c) 1982, 2011, Oracle and
/or
its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE =
/u01/oracle/oradata/ora11g/users01
.dbf
Page 171 is marked corrupt
Corrupt block relative dba: 0x010000ab (
file
4, block 171)
Bad check value found during dbv:
Data
in
bad block:
type
: 6
format
: 2 rdba: 0x010000ab
last change scn: 0x0b8c.3c014bfe
seq
: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value
in
tail
: 0x4bfe0602
check value
in
block header: 0x6e0c
computed block checksum: 0xb5bc
DBVERIFY - Verification complete
Total Pages Examined : 7680
Total Pages Processed (Data) : 3775
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 167
Total Pages Failing (Index): 0
Total Pages Processed (Other): 744
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 2993
Total Pages Marked Corrupt : 1
Total Pages Influx : 1
Total Pages Encrypted : 0
Highest block SCN : 1006717955 (2956.1006717955)
|
尝试查询数据
SQL>
select
count
(*)
from
t_xifenfei;
select
count
(*)
from
t_xifenfei
*
ERROR
at
line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 171)
ORA-01110: data file 4:
'/u01/oracle/oradata/ora11g/users01.dbf'
|
bbed验证坏块
BBED>
set
block 171
BLOCK
# 171
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 0x010000ab
ub4 bas_kcbh @8 0x3c014bfe
ub2 wrp_kcbh @12 0x0b8c
ub1 seq_kcbh @14 0x02
ub1 flg_kcbh @15 0x04 (KCBHFCKV)
ub2 chkval_kcbh @16 0x6e0c <--注意该值未变化
ub2 spare3_kcbh @18 0x0000
BBED> verify
DBVERIFY - Verification starting
FILE =
/u01/oracle/oradata/ora11g/users01
.dbf
BLOCK = 171
Block 171 is corrupt
Corrupt block relative dba: 0x010000ab (
file
0, block 171)
Bad check value found during verification
Data
in
bad block:
type
: 6
format
: 2 rdba: 0x010000ab
last change scn: 0x0b8c.3c014bfe
seq
: 0x2 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value
in
tail
: 0x4bfe0602
check value
in
block header: 0x6e0c
computed block checksum: 0xb5bc
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
Message 531 not found; product=RDBMS; facility=BBED
|
这里通过dbv,bbed,select table都证明rman能够标记block为Corrupt.
这里需要分析:block已经被标记,那证明该块肯定有修改,也就是说chkval_kcbh一定要变化,但是这里没有变化,证明该处异常
bbed修复rman生成坏块
BBED>
sum
apply
Warning: contents of previous BIFILE will be lost. Proceed? (Y
/N
) y
Check value
for
File 0, Block 171:
current = 0xdbb0, required = 0xdbb0
BBED> verify
DBVERIFY - Verification starting
FILE =
/u01/oracle/oradata/ora11g/users01
.dbf
BLOCK = 171
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
Message 531 not found; product=RDBMS; facility=BBED
|
bbed测试坏块已经修复
dbv验证坏块
[oracle@xifenfei ~]$ dbv
file
=
/u01/oracle/oradata/ora11g/users01
.dbf
DBVERIFY: Release 11.2.0.3.0 - Production on Sun Jan 20 10:01:46 2013
Copyright (c) 1982, 2011, Oracle and
/or
its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE =
/u01/oracle/oradata/ora11g/users01
.dbf
DBVERIFY - Verification complete
Total Pages Examined : 7680
Total Pages Processed (Data) : 3776
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 167
Total Pages Failing (Index): 0
Total Pages Processed (Other): 744
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 2993
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 1006717955 (2956.1006717955)
|
dbv测试坏块也被修复
查询表验证
SQL>
select
count
(*)
from
t_xifenfei;
COUNT
(*)
----------
9
|
数据也可以正常查询,证明rman的坏块问题通过bbed解决
总结说明
1.我们可以通过rman的clear命令来标记坏块(BLOCKRECOVER DATAFILE file# BLOCK block1#, block2#, block3#… CLEAR ;)
2.我们可以通过bbed的sum apply命令来修复该类型坏块