Monday, August 11, 2014

RDBMS -- Using BBED (For Oracle Internal Use Only!)

It was a long time ago, but I find this work interesting and  want to share it in this blog..

In one of our test instance, we encountered ORA-01161: database name ABYSDB in file header does not match given name of ABYSTEST error.
The error message was self explanatory..
Basically we had a datafile with a wrong file header .. We were cloning the database ABYSDB to ABYSTEST , and  the database name in the file header of the database file system01.dbf was remained as ABYSDB..
This error was the result of a failed recovery session and the database was an Oracle 10gR2..

As the problem was in a TEST instance, we didnt have anything to lose. So I have used BBED to correct the file header..
BBED is a tool that can be used as a block editor.
Using BBED, we can update/read data blocks even if our instance is shutdown..
We can corrupt, uncorrupt,change or recover the data we need using this tool. However, BBED tool must not be used by database administrators, and it is stated as "Oracle Internal Use Only".. That's why it is not linked, so can not be used directly..

Anyways, as this was a TEST instance, I have used it and it pretty much helped me for saving the day.

What I did was;

Firstly, I have linked and prepared bbed ;

make -f ins_rdbms.mk BBED=$ORACLE_HOME/bin/BBED $ORACLE_HOME/bin/BBED

Then, I started BBED cli ;

 bbed
Password: -- The password is blockedit

BBED: Release 2.0.0.0.0 - Limited Production 

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


************* !!! For Oracle Internal Use only !!! ***************

To see the data that supposed to be written in my problematic datafile, I have dump a proper datafile using BBED, and examined the output..

BBED>set offset 0
BBED> dump
 File: /yedek/oradata/drsys01.dbf (0)
 Block: 1                Offsets:    0 to  511           Dba:0x00000000
------------------------------------------------------------------------
 0ba20000 0100c000 00000000 00000104 320b0000 00000000 0000200a 355e19bb
 41425953 54455354 01000000 000a0000 00200000 03000300 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 ac160000 00000000 fcf35923 6880872d 97e1b348 7a050000 3ce0cf2c
 16767de8 77050000 01000000 fd4e0100 24d5ab2d fc4e0100 16767de8 77050000
 3ce0cf2c 01000000 31020000 02000000 10000000 02000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 000a0000 00000000
 00000000 00000000 00000000 03000000 05004452 53595300 00000000 00000000
 00000000 00000000 00000000 00000000 03000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 5cd3c52c a4614add 77050000 56255229 79050000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

 00000000 e30f608c 7a050000 12d3ab2d 01000160 bb010000 24090000 10000000

Then I have dumped the problematic datafile and saw the difference.


BBED> dump
 File: /yedek/oradata/system01.dbf (0)
 Block: 1                Offsets:    0 to  511           Dba:0x00000000
------------------------------------------------------------------------
 0ba20000 01004000 00000000 00000104 e9d70000 00000000 0000200a 355e19bb
 41425953 44420000 cd074600 00000300 00200000 01000300 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 79014000 06000000 00000000 e8f35923 5cd3c52c a4614add 77050000 3fe5ab2d
 7d7ea391 7a050000 01000120 72870100 5db5ab2d 71870100 7d7ea391 7a050000
 3fe5ab2d 01000000 7c4b0000 4a0a0200 10000000 02000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000300 00000000
 00000000 00000000 00000000 00000000 06005359 5354454d 00000000 00000000
 00000000 00000000 00000000 00000000 01000000 00000000 00000000 62d3c52c
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0a000a00
 10d0c52c 337749dd 77050000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 7d7ea391 7a050000 3fe5ab2d 01000000 7c4b0000 4a0a0200 10000000

select UTL_RAW.CAST_TO_VARCHAR2('4142595344420000') from dual;
Output: ABYSDB

So 41422953 must be -> ABYS and 44420000  must be -> DB ..
That 'is -> if I could update 44420000 with 54455354(which means TEST), my problem would be fixed.. 

To be able to do that, I put BBED into edit to mode and updated the data , as follows..

BBED> set mode edit

        MODE            Edit

To able to modify  44420000, my offset should be 36,37,38,39.. 
As one line represent 32 bytes and one word contains 4 byte -> One line + one word = 32 +4 = 36
The word TEST was 4 byte so I had to update one word ..

So I updated the data residing on block from offset 36 to offset 39..

BBED> modify /x 54 offset 36
BBED>modify /x 45 offset 37
BBED>modify /x 53 offset 38
BBED> modify /x 54 offset 39

After the update, recomputed the block checksum and dumped the data again to see the data if changed properly..

BBED> sum apply
Check value for File 0, Block 1:
current = 0x84aa, required = 0x84aa


BBED> set offset 0
        OFFSET          0

BBED> dump
 File: /yedek/oradata/system01.dbf (0)
 Block: 1                Offsets:    0 to  511           Dba:0x00000000
------------------------------------------------------------------------
 0ba20000 01004000 00000000 00000104 aa840000 00000000 0000200a 355e19bb
 41425953 54455354 cd074600 00000300 00200000 01000300 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 79014000 06000000 00000000 e8f35923 5cd3c52c a4614add 77050000 3fe5ab2d
 7d7ea391 7a050000 01000120 72870100 5db5ab2d 71870100 7d7ea391 7a050000
 3fe5ab2d 01000000 7c4b0000 4a0a0200 10000000 02000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000300 00000000
 00000000 00000000 00000000 00000000 06005359 5354454d 00000000 00000000
 00000000 00000000 00000000 00000000 01000000 00000000 00000000 62d3c52c
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0a000a00
 10d0c52c 337749dd 77050000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 7d7ea391 7a050000 3fe5ab2d 01000000 7c4b0000 4a0a0200 10000000

Okay, that was it. I updated the dbname in the system01.dbf using BBED.
After the update , I retried the failing operation and succeeded..

Note that: Never use BBED in a Production system.. Also never use it if your test instance is a critical one.. This is just an example.. BBED should not be used without Oracle Support.

No comments :

Post a Comment