BBED> dump file 6 block 36
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 0 to 511 Dba:0x01800024
------------------------------------------------------------------------
06020000 24008001 9dcc0300 00000106 d3aa0000 01000000 4f190000 9bcc0300
00000000 02003200 21008001 07000a00 54000000 84238000 17000b00 01200000
9dcc0300 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00010100 ffff1400 931f7b1f 7b1f0000 0100931f 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
BBED>
offset 偏移量 从 0 到 511 单位是字节,数据块是8k的,想看完全就要扩大offset的范围
BBED> dump file 6 block 36 count 8200
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 0 to 8191 Dba:0x01800024
------------------------------------------------------------------------
06020000 24008001 9dcc0300 00000106 d3aa0000 01000000 4f190000 9bcc0300
00000000 02003200 21008001 07000a00 54000000 84238000 17000b00 01200000
9dcc0300 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00010100 ffff1400 931f7b1f 7b1f0000 0100931f 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 0000002c 01010161 01069dcc
<32 bytes per line>
BBED>
Offsets: 0 to 8191 1024 * 8 = 8192个字节,正好8K。注意最后的几个字节中,有个61,这个就是表中的那条数据,验证一下。
SQL> select * from haocp;
A
----------
a
SQL> select dump(a,1016) from haocp;
DUMP(A,1016)
--------------------------------------------------------------------------------
Typ=1 Len=1 CharacterSet=ZHS16GBK: 61
字符a对应的16进制编码是61。如果数据量大的话,可以用find命令查找
BBED> help find
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
BBED> set file 6
FILE# 6
BBED> set block 36
BLOCK# 36
BBED> find 97 curr
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
BBED> find /x 61 curr
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
在find之前先设置想要查找的 file 和 block,默认是十进制的ascii编码,/x 表示16进制,find的结果显示出offset,即字符出现的位置。
下面试试修改他,把a改成b。
BBED> help modify
MODIFY[/x|d|u|o|c] numeric/character string
[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
BBED> modify 98 file 6 block 36 offset 8187
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6201069d cc
<32 bytes per line>
修改完了以后,由61变成62了,不过这时数据块是损坏状态,试一下。
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/oracle/oradata/test/users01.dbf
BLOCK = 36
Block 36 is corrupt
***
Corrupt block relative dba: 0x01800024 (file 0, block 36)
Bad check value found during verification
Data in bad block -
type: 6 format: 2 rdba: 0x01800024
last change scn: 0x0000.0003cc9d seq: 0x1 flg: 0x06
consistency value in tail: 0xcc9d0601
check value in block header: 0xaad3, computed block checksum: 0x300
spare1: 0x0, spare2: 0x0, spare3: 0x0
***
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
Total Blocks Marked Corrupt : 1
有1个块被标识为损坏,从刚才备份的那个文件覆盖它。
BBED> copy file 2 block 36 to file 6 block 36
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 0 to 511 Dba:0x01800024
------------------------------------------------------------------------
06020000 24008001 9dcc0300 00000106 d3aa0000 01000000 4f190000 9bcc0300
00000000 02003200 21008001 07000a00 54000000 84238000 17000b00 01200000
9dcc0300 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00010100 ffff1400 931f7b1f 7b1f0000 0100931f 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
从刚才关闭数据库时cp的文件中复制第36个块来覆盖当前的块,覆盖完了再检查一下。
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/oracle/oradata/test/users01.dbf
BLOCK = 36
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
好了,看看8187的情况
BBED> dump file 6 block 36 offset 8187
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
是原来的61,也就是字符 a 。再次改过来,试试回滚的命令。
BBED> modify /x 62 file 6 block 36 offset 8187
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6201069d cc
<32 bytes per line>
BBED> undo
BBED> modify /x 61 filename '/u01/oracle/oradata/test/users01.dbf' block 36. offset 8187.
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
undo就相当于sqlplus里面的 rollback 不过是回滚上一步,而不是所有操作。
下面试试revert,不过要重新登陆,因为revert是回滚这次登陆以来所有的操作。
BBED> dump file 6 block 36 offset 8187
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
BBED> modify /x 62 file 6 block 36 offset 8187
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6201069d cc
<32 bytes per line>
BBED> revert
All changes made in this session will be rolled back. Proceed? (Y/N) y
Reverted file '/u01/oracle/oradata/test/users01.dbf', block 36
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
BBED> dump file 6 block 36 offset 8187
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
个人感觉bbed主要用在数据库恢复的时候,比如由于误操作把数据库的字典表的信息改错了,导致数据库不能启动了,此时用bbed在脱机的情况下把字典表的值再改回来。使数据库open。
用modify改完数据之后,block处于corrupt状态,所以要通过sum命令计算并应用checksum值,使block状态恢复正常。
SQL> select * from haocp;
A
----------
a
BBED> dump file 6 block 36 offset 8187
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6101069d cc
<32 bytes per line>
BBED> modify /x 62 file 6 block 36 offset 8187
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/oracle/oradata/test/users01.dbf (6)
Block: 36 Offsets: 8187 to 8191 Dba:0x01800024
------------------------------------------------------------------------
6201069d cc
<32 bytes per line>
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/oracle/oradata/test/users01.dbf
BLOCK = 36
Block 36 is corrupt
***
Corrupt block relative dba: 0x01800024 (file 0, block 36)
Bad check value found during verification
Data in bad block -
type: 6 format: 2 rdba: 0x01800024
last change scn: 0x0000.0003cc9d seq: 0x1 flg: 0x06
consistency value in tail: 0xcc9d0601
check value in block header: 0xaad3, computed block checksum: 0x300
spare1: 0x0, spare2: 0x0, spare3: 0x0
***
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
修改完之后block的状态是corrupt的。用sum命令使之有效。
BBED> help sum
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
BBED> sum file 6 block 36
Check value for File 6, Block 36:
current = 0xaad3, required = 0xa9d3
此时 current checksum 是0xaad3,required checksum 是 0xa9d3
BBED> sum file 6 block 36 apply
Check value for File 6, Block 36:
current = 0xa9d3, required = 0xa9d3
加上apply参数,使checksum一致。此时block状态恢复正常。
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/oracle/oradata/test/users01.dbf
BLOCK = 36
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> select * from haocp;
A
----------
a
还是 a ,重启一下。
SQL> startup force
ORACLE instance started.
Total System Global Area 185668648 bytes
Fixed Size 451624 bytes
Variable Size 117440512 bytes
Database Buffers 67108864 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from haocp;
A
----------
b
有人编译不成功,提示编译错误。
我这里简单写一下:
环境linux as4 oracle9204
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
./bbed
口令:blockedit