Oracle bbed directly modifies database block blocks

Source: Internet
Author: User

--place Lib Bbedus.msb and Bbedus.msg under $ORACLE_HOME/RDBMS/MESG
--place Lib sbbdpt.o and SSBBDED.O under $oracle_home/rdbms/lib
--Executed under $oracle_home/rdbms/lib: [[email protected] lib]$ make-f ins_rdbms.mk $ORACLE _home/rdbms/lib/bbed
After execution, a bbed executable is generated under Lib

default password;
Blockedit

Oracle bbed directly modifies database block blocks
Bbed is an abbreviation for the English block Browse block edit, a tool for directly viewing and modifying data file data.

Create a new table and insert 5 test data:
CREATE TABLE Chenlintest (ID number (5), name varchar (TEN)) tablespace users;

sql> INSERT INTO chenlintest values (1, ' AA ');
1 row created.
sql> INSERT INTO chenlintest values (888, ' chenlin ');
1 row created.
sql> INSERT into chenlintest values (999, ' China ');
1 row created.
sql> INSERT into chenlintest values (999, ' USA ');
1 row created.
sql> INSERT into chenlintest values (1001, ' Sydney ');
1 row created.
Commit complete.
Sql> select * from Chenlintest;
ID NAME
---------- ----------
1 AA
999 USA
1001 Sydney
888 Chenlin
999 China

Sql> SELECT
DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) Rel_fno,
Dbms_rowid.rowid_block_number (ROWID) Blockno,
Dbms_rowid.rowid_row_number (ROWID) ROWNO,
User_id,username from T
where RowNum <6;

Rel_fno blockno ROWNO ID NAME
---------- ---------- ---------- ---------- ----------
4 234300 0 1 AA
4 234300 1 999 USA
4 234300 2 1001 Sydney
4 234300 3 888 Chenlin
4 234300 4 999 China

As you can see from the SQL statement above, all the data for the Chenlintest table is on the No. 234300 block block of file 4th.
Now we're trying to change the AA, which is the first line.

Set up 2 configuration files for bbed,
One is the file.txt file:
This file corresponds to 3 columns, file_id,path,block_size, which can be generated using sql:

Select File#| | ' ' | | name| | ' ' | | bytes from V$datafile;

[Email protected] home]$/home/oracle> cat file.txt

1/OPT/ORACLE/ORADATA/GE01/SYSTEM01.DBF 870318080
2/OPT/ORACLE/ORADATA/GE01/USERS_CMS.DBF 524288000
3/OPT/ORACLE/ORADATA/GE01/SYSAUX01.DBF 1866465280
4/OPT/ORACLE/ORADATA/GE01/USERS01.DBF 18971361280
5/OPT/ORACLE/ORADATA/GE01/USERS02.DBF 1073741824
6/OPT/ORACLE/ORADATA/GE01/PERSTAT.DBF 209715200
7/OPT/ORACLE/ORADATA/GE01/UNDOTBS02.DBF 1073741824
8/OPT/ORACLE/ORADATA/GE01/TTUSER.DBF 41943040
9/opt/oracle/oradata/ge01/idx_2k 20971520

One is bbed.txt:

This file is bbed configuration file, configure the Blocksize,listfile,mode three parameters, we start, use this file to pull up bbed.
Sql> Show Parameter Db_block_size
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
Db_block_size integer 8192
Sql>

[email protected] home]$ cat Bbed.txt
blocksize=8192
Listfile=/home/oracle/file.txt
Mode=edit
/*
Mode=edit default is borwser browse mode
You can use Set mode edit to toggle
*/
--Installation of bbed
CD $ORACLE _home/rdbms/lib
Make-f ins_rdbms.mk $ORACLE _home/rdbms/lib/bbed
*/
--Enter bbed
[Email protected] home]$./bbed parfile=/home/oracle/bbed.txt or directly./bbed
[Email protected] lib]$ pwd
/opt/oracle/product/10g/rdbms/lib
[email protected] lib]$ LL | grep bbed
-rwxr-xr-x 1 Oracle Oinstall 536154 may 14:47 bbed
[Email protected] lib]$
[Email protected] lib]$./bbed
Password:blockedit
Bbed:release 2.0.0.0.0-limited Production on Mon 14 17:45:20 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal with only!!! ***************

Bbed> Help all view all command aids

Most commonly used are show, map, dump, set DBA, set file, set block, etc.
Here are a few common:
Set to set the current environment
Show looks at the current environment parameter, similar to the command with the same name as Sqlplus.
Dump lists the contents of the specified block
Find finds the specified string in the specified block, with the result that the string is displayed, its offset is--offset, and the offset is the number of bytes in the block
Modify modifies the specified offset value for the specified block and can be modified online.
Copy copy the contents of a block to another block
Verify check if the current environment has bad blocks
Sum calculates the block's checksum,modify after the block is identified as a bad block, current checksum and reqired checksum inconsistent, the sum command can be counted

Calculates a new checksum and applies it to the current block.
Undo rollback of the current modification operation, if the hand mistakenly done wrong, undo a bit OK, back to the original state.
Revert rollback all previous modification actions, meaning undo all

Bbed> Show
file# 0
block# 1
OFFSET 0
DBA 0x00000000 (0 0,1)
FILENAME
Bifile BIFILE.BBD
ListFile
BLOCKSIZE 8192
MODE Browse
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE LOG.BBD
SPOOL No

Bbed> Set File 4
Bbed-00312:no listfile Specified/* listfile is empty, stating that our newly created file.txt was not introduced correctly */
bbed> set list '/home/oracle/file.txt '
Listfile/home/oracle/file.txt
bbed> Info
file# Name Size (blks)
-----  ----                                                        ----------
1/OPT/ORACLE/ORADATA/GE01/SYSTEM01.DBF 106240
2/OPT/ORACLE/ORADATA/GE01/USERS_CMS.DBF 64000
3/OPT/ORACLE/ORADATA/GE01/SYSAUX01.DBF 227840
4/OPT/ORACLE/ORADATA/GE01/USERS01.DBF 524287
5/OPT/ORACLE/ORADATA/GE01/USERS02.DBF 131072
6/OPT/ORACLE/ORADATA/GE01/PERSTAT.DBF 25600
7/OPT/ORACLE/ORADATA/GE01/UNDOTBS02.DBF 131072
8/OPT/ORACLE/ORADATA/GE01/TTUSER.DBF 5120
9/opt/oracle/oradata/ge01/idx_2k 2560
Bbed> Set File 4
file# 4
--4 file is/opt/oracle/oradata/ge01/users01.dbf
Bbed> Set Block 234300
block# 234300
Bbed> Set Block +10
block# 234310
Bbed> Set block-10
block# 234300
--offset is offset from a block, and can be manipulated with + and-

There are many kinds of, not much to write, see: http://blog.csdn.net/tianlesoftware/article/details/5006580
Bbed> Map
File:/OPT/ORACLE/ORADATA/GE01/USERS01.DBF (4)
block:234300 dba:0x0103933c
------------------------------------------------------------
KTB Data Block (table/cluster)
struct KCBH, Bytes @0
struct KTBBH, Bytes @20
struct KDBH, Bytes @100
struct kdbt[1], 4 bytes @114
SB2 Kdbr[5] @118
Ub1 freespace[7980] @128
Ub1 Rowdata[80] @8108
UB4 Tailchk @8188

After map, we can see the structure of the real block, the storage in the block is stored from the bottom up, (@ is the offset),
FreeSpace on the real row data rowdata, this @8108 begins, to @8188, and the data content is placed behind it.
As we said above, to change the AA data on these 2 offsets directly.
Bbed> Set Offset 8108
OFFSET 8108
Bbed> dump/v--View the data value of offset 8180-8192
File:/OPT/ORACLE/ORADATA/GE01/USERS01.DBF (4)
block:234300 offsets:8108 to 8191 dba:0x0103933c
-------------------------------------------------------
2c020203 c20b0206 7379646e 65792c02 L,....... Sydney,.
0203c20a 64037573 612c0202 03c20a64 l .... d.usa,..... D
05636869 6e612c00 0203c209 59076368 L.,..... y.ch
656e6c69 6e3c0202 02c10402 63633c02 l enlin<......cc<.
0202c103 0262622c 000202c1 02026161 l ... bb,...... AA
04066fe1 L.. O.
<16 bytes per line>

[email protected]> select dump (' AA ', 1016) from dual;
DUMP (' AA ', 1016)
----------------------------------------------------------------------------------
typ=96 len=2 characterset=us7ascii:61,61

Before find, set the file and block you want to find, by default is the ASCII encoding of Decimal,/X for 16, and the result of find shows offset, the character

The location that appears.
Through find, the "AA" location, we found that 6161 is a AA
If you are not sure, you can use dump to implement

The first method of find:
bbed> find/x 6161 Curr
File:/OPT/ORACLE/ORADATA/GE01/USERS01.DBF (4)
block:234300 offsets:8186 to 8191 dba:0x0103933c
------------------------------------------------------------------------
61610406 6fe1
<32 bytes per line>

The second method of find:
Bbed>
bbed> find/c AA
File:/OPT/ORACLE/ORADATA/GE01/USERS01.DBF (4)
block:234300 offsets:8186 to 8191 dba:0x0103933c
------------------------------------------------------------------------
61610406 6fe1
<32 bytes per line>

Through these 2 methods, find and confirm AA between 8186 and 8191, try to modify him below, change AA to BB
Bbed> modify/c ABCDEFG
Bbed-00215:editing not allowed in BROWSE mode

Bbed> Set Mode Edit
MODE Edit

Bbed> modify/c BB (Note the length, cannot exceed the length set when the table is built, otherwise it will be wrong)
Warning:contents of previous bifile'll be lost. Proceed? (y/n) Y
File:/OPT/ORACLE/ORADATA/GE01/USERS01.DBF (4)
block:234300 offsets:8186 to 8191 dba:0x0103933c
------------------------------------------------------------------------
61626364 6566
<32 bytes per line>
--Let Oracle perform checksum operations
bbed> Sum dba 4,234300
Check value for File 4, Block 234300:
Current = 0xd268, required = 0x3405
--Direct application
bbed> sum dba 4,234300 apply;
Check value for File 4, Block 234300:
Current = 0x3405, required = 0x3405
--Verify that the modification is successful
Bbed> Verify
Dbverify-verification starting
FILE =/opt/oracle/oradata/ge01/users01.dbf
BLOCK = 234300

--Verify that the modification is successful
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

/*
Total Blocks Marked corrupt:0, indicating that the wood was wrong
In actual work, if you find that the modification is wrong, you can roll back the operation through Undo,revert.
Please note the difference between undo and revert in the most commonly used basic commands above.
*/
Sql> select * from Chenlintest;

ID NAME
---------- ----------
1 AA
999 USA
1001 Sydney
888 Chenlin
999 China

--found no change, consider whether you need to empty the buffer cache
Sql> alter system flush Buffer_cache;
System altered.
Sql> select * from Chenlintest;
ID NAME
---------- ----------
1 BB
999 USA
1001 Sydney
888 Chenlin
999 China
Finish the work, the next time to continue to write when the database, due to a data file inconsistent, start not to come, change how to modify the DataFile header SCN number. Make it

Consistent with the SCN number of the control file!

Oracle bbed directly modifies database block blocks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.