How to modify datafile header through BBED

Look back upon this month I remembered that, I was successfully modified datafile header through BBED, but didn’t write about it at all. And I figured out, it is isn’t right, because when I will need to use it again I will have to struggle to remember.

Some time ago, I helped to migrate Oralce database from Windows platform to Linux platform. During migration was happened some strange situation. When RMAN finished his “convert datafile” work, controlfile wasn’t created successfully, stumbled upon an error ORA-01161. Off course I used “SET DATABASE” when was try to create controlfile. And what is more interesting all files was successfully updated their headers except only one file.

Bellow I’m described how we can modify data in the header.

If you haven’t bbed you can compile it. But you need some library from Oracle RDBMS 10g the same platform as target RDBMS.

$ORACLE_HOME/rdbms/lib/ssbbded.o
$ORACLE_HOME/rdbms/lib/sbbdpt.o
$ORACLE_HOME/rdbms/mesg/bbedus.msb
$ORACLE_HOME/rdbms/mesg/bbedus.msg

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

When you start BBED it will ask you for a password. The password is: blockedit

$ORACLE_HOME/bin/bbed filename=/path/file.dbf password=blockedit mode=edit

BBED: Release 2.0.0.0.0 - Limited Production on Mon Dec 29 12:54:59 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

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

BBED> dump
 File: /path/file.dbf (0)
 Block: 1                Offsets:    0 to  499           Dba:0x00000000
------------------------------------------------------------------------
 0ba20000 0100c023 00000000 00000104 a5d00000 00000000 0000200b b38db189 
 56495336 00000000 ac720000 00010000 00200000 8f000300 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 d8df0000 00000000 0fd40c2c ea79ae33 f9be6799 190b0000 00000000 
 00000000 00000000 00000400 0d030000 0dc3b133 0c030000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 3e000000 03005844 42000000 00000000 00000000 
 00000000 00000000 00000000 00000000 8f000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 5c79ae33 f8bd6799 190b0000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 75aadd99 190b250a 43cfb433 01000000 

 <32 bytes per line>

According this “32 bytes per line” we can find offset. From 29 to 32 bytes this is a DBID (b38db189). From 33 to 36 bytes this is a db name (56495336). Let’s recognize what exactly ID and name does have our file.

SQL> select to_number('b38db189','xxxxxxxx') from dual;

TO_NUMBER('B38DB189','XXXXXXXX')
--------------------------------
                      3012407689

SQL> select utl_raw.cast_to_varchar2('56495336') from dual;

UTL_RAW.CAST_TO_VARCHAR2('56495336')
--------------------------------------------------------------------------------
VIS6

But we know that it should be DBID: 2310114739 and DB name: ORCL. So let’s try to modify it.

SQL> select to_char('2310114739','xxxxxxxx') from dual;

TO_CHAR('
---------
 89b18db3


SQL> select dump('ORCL',16) from dual;

DUMP('ORCL',16)
-------------------------
Typ=96 Len=4: 4f,52,43,4c

BBED can’t modify whole byte that’s why we need to split up per 4 bits.

For DBID:

BBED> modify /x 89b1 offset 28

BBED> modify /x 8db3 offset 30

For DB name:

BBED> modify /x 4f52 offset 32

BBED> modify /x 434c offset 34

Don’t forget take care about checksum.

BBED> sum
Check value for File 0, Block 1:
current = 0xd0a5, required = 0xb7aa

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

Check values.

BBED> dump offset 0
 File: /path/file.dbf (0)
 Block: 1                Offsets:    0 to  499           Dba:0x00000000
------------------------------------------------------------------------
 0ba20000 0100c023 00000000 00000104 aab70000 00000000 0000200b 89b18db3 
 4f52434c 00000000 ac720000 00010000 00200000 8f000300 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 d8df0000 00000000 0fd40c2c ea79ae33 f9be6799 190b0000 00000000 
 00000000 00000000 00000400 0d030000 0dc3b133 0c030000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 3e000000 03005844 42000000 00000000 00000000 
 00000000 00000000 00000000 00000000 8f000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 5c79ae33 f8bd6799 190b0000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 75aadd99 190b250a 43cfb433 01000000 

 <32 bytes per line>

BBED> exit

And re-create controlfile again.

Advertisements

2 thoughts on “How to modify datafile header through BBED

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s