Simulating Oracle database bad blocks using bbed

Source: Internet
Author: User

Bbed (Oracleblockbrowerandeditor tools), a tool for directly viewing and modifying data file data, is an internal tool for Oracle that can directly modify the contents of an Oracle data file block, which is useful in some extreme recovery scenarios. The tool is not supported by Oracle, so it is not generated by default and needs to be reconnected before it can be used.

1. Installing bbed

[[email protected] lib]$ pwd/u02/app/product/10.2.0/db_1/rdbms/lib[[email protected] lib]$ make-f ins_ Rdbms.mk $ORACLE _home/rdbms/lib/bbed-bash:make-f: Command not found[[email protected] lib]$ make-f ins_rdbms.mk $ Oracle_home/rdbms/lib/bbedlinking bbed Utility (bbed) rm-f/u02/app/product/10.2.0/db_1/rdbms/lib/bbedgcc-o/u02/app /product/10.2.0/db_1/rdbms/lib/bbed-l/u02/app/product/10.2.0/db_1/rdbms/lib/-L/u02/app/product/10.2.0/db_1/lib /-l/u02/app/product/10.2.0/db_1/lib/stubs/-l/usr/lib-lirc/u02/app/product/10.2.0/db_1/lib/s0main.o/u02/app/ PRODUCT/10.2.0/DB_1/RDBMS/LIB/SSBBDED.O/U02/APP/PRODUCT/10.2.0/DB_1/RDBMS/LIB/SBBDPT.O ' cat/u02/app/product/ 10.2.0/db_1/lib/ldflags '-lnsslb10-lncrypt10-lnsgr10-lnzjs10-ln10-lnnz10-lnl10/u02/app/product/10.2.0/db_1/rdbm S/lib/defopt.o-ldbtools10-lclntsh ' Cat/u02/app/product/10.2.0/db_1/lib/ldflags '-lnsslb10-lncrypt10-lnsgr10-lnzj S10-ln10-lnnz10-lnl10-lnro10 ' Cat/u02/app/product/10.2.0/db_1/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-lc Ore10-lnls10 ' Cat/u02/app/product/10.2.0/db_1/lib/ldflags '-LNSSLB10-LNCRYPT10-LNSGR10-LNZJS10-LN10-LNNZ10-LNL1 0-lnro10 ' Cat/u02/app/product/10.2.0/db_1/lib/ldflags '-lnsslb10-lncrypt10-lnsgr10-lnzjs10-ln10-lnnz10-lnl10-l  Client10-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/u02/app/product/10.2.0/db_1/lib/sysliblist '-wl,-rpath,/u02/app/product/10.2.0/db_1/lib-lm ' cat/u02/app/ Product/10.2.0/db_1/lib/sysliBlist '-ldl-lm-l/u02/app/product/10.2.0/db_1/lib[[email protected] lib]$ ll bbed-rwxr-xr-x 1 Oracle Oinstall 5507 5 10:34 bbed[[email protected] lib]$./bbedpassword:--Password defaults to blockeditbbed:release 2.0.0.0.0-limited Pr  Oduction on Thu Feb 5 11:12:15 2015Copyright (c) 1982, Oracle. All Rights reserved.*************!!! For Oracle Internal with only!!!                                                        bbed> Info file# Name Size (blks)--------- ----------

Oracledatabase 11g in the default does not provide bbed library files, but can be compiled with 10g files, you need to first copy the following files from 10g to the appropriate directory, and then perform the above connection command.

$ORACLE _HOME/RDBMS/LIB/SSBBDED.O

$ORACLE _HOME/RDBMS/LIB/SBBDPT.O

$ORACLE _HOME/RDBMS/MSG/BBEDUS.MSB

2. Connect bbed using the parameter file

--Query the data file of the current library and save it in a text file

Sql> Select File#| | ' ' | | name| | ' ' | | bytes from V$datafile; file#| | ' | | name| | ' | | BYTES--------------------------------------------------------------------------------1/u02/app/oradata/psdb/ SYSTEM01.DBF 5033164802/u02/app/oradata/psdb/undotbs01.dbf 367001603/u02/app/oradata/psdb/sysaux01.dbf 2621440004 /U02/APP/ORADATA/PSDB/USERS01.DBF 52428805/u02/app/oradata/psdb/example01.dbf 1048576006/u02/app/oradata/psdb/ LIVAN_TBS01.DBF 3145728006 rows selected.

--Note that the file number stored in the file is the same as the file# queried by our database.

[email protected] lib]$ cat ~/psdb_file.txt 1/u02/app/oradata/psdb/system01.dbf 5033164802/u02/app/oradata/psdb/ UNDOTBS01.DBF 367001603/u02/app/oradata/psdb/sysaux01.dbf 2621440004/u02/app/oradata/psdb/users01.dbf 52428805/ U02/APP/ORADATA/PSDB/EXAMPLE01.DBF 1048576006/u02/app/oradata/psdb/livan_tbs01.dbf 314572800

--bbed logging in with a parameter file

[email protected] lib]$ cat ~/bbed_parameter.txt blocksize=8192listfile=/home/oracle/psdb_file.txtmode=edit[[ Email protected] lib]$./bbed parfile=/home/oracle/bbed_parameter.txt Password:BBED:Release 2.0.0.0.0-limited  Production on Thu Feb 5 11:39:23 2015Copyright (c) 1982, Oracle. All Rights reserved.*************!!! For Oracle Internal with only!!!                                                        bbed> Info file# Name Size (blks)---------                               ----------1/U02/APP/ORADATA/PSDB/SYSTEM01.DBF 61440 2/u02/app/oradata/psdb/undotbs01.dbf 4480 3/u02/app/oradata/p                                  SDB/SYSAUX01.DBF 32000 4/u02/app/oradata/psdb/users01.dbf 640 5/U02/APP/ORADATA/PSDB/EXAMPLE01.DBF 12800 6/u02/app/oradata/psdb/livan_     Tbs01.dbf                       38400bbed>  

3. Create a Test object

[[email protected] lib]$ sqlplus livan/livansql*plus:release 10.2.0.4.0-production on Thu Feb 5 11:42:36 2015Copyright (c) 1982, Oracle.  All rights reserved.connected to:oracle Database 10g Enterprise Edition Release 10.2.0.4.0-productionwith the Partitioni Ng, OLAP, Data Mining and Real application testing optionssql> CREATE TABLE Test (ID int,name varchar2 (30)); Table created. sql> INSERT INTO test values (1, ' Beijing '); 1 row created. sql> INSERT INTO test values (2, ' Shanghai '); 1 row created. sql> INSERT INTO test values (3, ' Shandong '); 1 row created. Sql> commit; Commit complete.

--View the data block distribution of the test object

Sql> Select   2  dbms_rowid. ROWID_RELATIVE_FNO (ROWID) FNO,  3  dbms_rowid. Rowid_block_number (ROWID) bno,  4  dbms_rowid. Rowid_row_number (ROWID) Rowno,  5  name from   test;       FNO        BNO      ROWNO NAME------------------------------------------------------------         6          0 Beijing         6          1 Shanghai         6          2 Shandong

4. Editing data blocks with bbed

[[email protected] lib]$./bbed parfile=/home/oracle/bbed_parameter.txt Password:BBED:Release 2.0.0.0.0-  Limited Production on Thu Feb 5 12:33:32 2015Copyright (c) 1982, Oracle. All Rights reserved.*************!!! For Oracle Internal with only!!!                                                        bbed> Info file# Name Size (blks)---------                               ----------1/U02/APP/ORADATA/PSDB/SYSTEM01.DBF 61440 2/u02/app/oradata/psdb/undotbs01.dbf 4480 3/u02/app/oradata/p                                  SDB/SYSAUX01.DBF 32000 4/u02/app/oradata/psdb/users01.dbf 640 5/U02/APP/ORADATA/PSDB/EXAMPLE01.DBF 12800 6/u02/app/oradata/psdb/livan_ TBS01.DBF 38400bbed> Set dba 6,12 dba 0x0180000c (25165836 6,12) bbed> Dump /V DBA 6,12 offset 0 File:/u02/app/oradata/psdb/livan_tbs01.dbf (6) Block:12 offsets:0 to 127 dba:0x0180000c -------------------------------------------------------06a20000 0c008001 60d40700 00000506 L.? .....`?..... 5c4d0000 01000000 c9ce0000 51d40700 l \m ... The noon. Q?. 00000000 02003200 09008001 05002c00 l ... 2 .......... 1c010000 b1058000 f1000500 03200000 l ....?..? ... .. 60d40700 00000000 00000000 00000000 L '?............. 00000000 00000000 00000000 00000000 L ...... ..... 00000000 00010300 ffff1800 6c1f541f l .... l.t. 541f0000 03008a1f 7b1f6c1f 00000000 L T ..... ..... {. L ..... <16 bytes per line>bbed> modify/x 12345678 dba 6,12 offset 0 File:/u02/app/oradata/psdb/livan_tbs01.db F (6) Block:12 offsets:0 to 127 dba:0x0180000c---------------------------------------------- --------------------------12345678 0c008001 60d40700 00000506 5c4d0000 01000000 c9ce0000 51d40700 00000000 02003200 0900 8001 05002c00 1c010000 b1058000f1000500 03200000 60d40700 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010300 ffff1800 6c1 f541f 541f0000 03008a1f 7b1f6c1f 00000000 <32 bytes per line>bbed> sum dba 6,12 applycheck value for File 6, Blo CK 12:current = 0xa31e, required = 0xa31e

5. Login Sqlplus Verification Form

[[email protected] lib]$ sqlplus '/as sysdba ' sql*plus:release 10.2.0.4.0-production on Thu Feb 5 12:50:22 2015Copyright (c) 1982, Oracle.  All rights reserved.connected to:oracle Database 10g Enterprise Edition Release 10.2.0.4.0-productionwith the Partitioni Ng, OLAP, Data Mining and Real application testing optionssql> conn livan/livanconnected.sql> select * from Test;
   id NAME----------------------------------------         1 Beijing         2 Shanghai         3 shandongsql> Conn/as Sysdbaconnected.sql> alter system flush Buffer_cache; System altered. Sql> Conn livan/livanconnected.sql> SELECT * FROM Test;select * FROM Test              *error @ line 1:ora-01578:oracle dat A block corrupted (file # 6, Block #) Ora-01110:data file 6: '/U02/APP/ORADATA/PSDB/LIVAN_TBS01.DBF '

6. Use the DBV tool to check for bad data blocks

[[email protected] lib]$ DBV file=/u02/app/oradata/psdb/livan_tbs01.dbfdbverify:release 10.2.0.4.0-production  On Thu Feb 5 12:50:05 2015Copyright (c) 1982, Oracle. All rights reserved. Dbverify-verification starting:file =/u02/app/oradata/psdb/livan_tbs01.dbfpage is marked CorruptCorrupt block RelA tive dba:0x0180000c (file 6, block) bad check value found during Dbv:data in bad Block:type:6 format:2 rdba:0x0180 000c last change scn:0x0000.0007d460 seq:0x5 flg:0x06 spare1:0x0 spare2:0x0 spare3:0x0 consistency value in tail:0x d4600605 Check value in block HEADER:0X4D5C computed block checksum:0x1607dbverify-verification completetotal Pages Ex Amined:38400total pages processed (data): 4Total pages failing (data): 0Total pages processed (Index): 0Tota  L pages Failing (Index): 0Total pages processed (other): 11Total pages processed (SEG): 0Total pages failing (SEG) : 0Total pages empty:38384total pages Marked corrupt: 1--found bad block total Pages influx:0highest block scn:513120 (0.513120) 

7. Use the Rman tool to check data files to verify bad blocks

[[email protected] lib]$ rman target/recovery manager:release 10.2.0.4.0-production on Thu Feb 5 12:54:21 2015Cop  Yright (c) 1982, Oracle. All rights reserved.connected to target Database:psdb (dbid=1410134833) rman> backup check logical validate database; Starting backup at 05-feb-15using target database control file instead of recovery catalogallocated Channel:ora_disk_1cha Nnel ora_disk_1:sid=141 devtype=diskchannel ora_disk_1:starting full datafile backupsetchannel ora_disk_1:specifying D Atafile (s) in Backupsetinput datafile fno=00001 name=/u02/app/oradata/psdb/system01.dbfinput datafile fno=00006 name=/ U02/app/oradata/psdb/livan_tbs01.dbfinput datafile fno=00003 name=/u02/app/oradata/psdb/sysaux01.dbfinput datafile fno=00005 name=/u02/app/oradata/psdb/example01.dbfinput datafile fno=00002 name=/u02/app/oradata/psdb/ Undotbs01.dbfinput datafile fno=00004 Name=/u02/app/oradata/psdb/users01.dbfchannel ora_disk_1:backup set Complete, Elapsed Time:00:00:25channel Ora_disk_1:starting full datafile Backupsetchannel ora_disk_1:specifying datafile (s) in backupsetincluding current contr OL file in backupsetincluding current SPFILE in Backupsetchannel ora_disk_1:backup set complete, elapsed Time:00:00:02fi nished Backup at 05-feb-15

----Check only for a data file

rman> backup Check logical validate DataFile 6; Starting backup at 05-feb-15using target database control file instead of recovery catalogallocated Channel:ora_disk_1cha Nnel ora_disk_1:sid=159 devtype=diskchannel ora_disk_1:starting full datafile backupsetchannel ora_disk_1:specifying D Atafile (s) in Backupsetinput datafile fno=00006 name=/u02/app/oradata/psdb/livan_tbs01.dbfchannel ora_disk_1:backup Set complete, elapsed time:00:00:01finished backup at 05-feb-15

--rman's test results were put in v$database_block_corruption.

Sql> select File#,block#,blocks from V$database_block_corruption;     file#     block#     BLOCKS------------------------------         6          1

8. Verify bad blocks with exp export tool

[Email protected] lib]$ exp Livan/livan file=/home/oracle/livan_table.dmp tables=testexport:release 10.2.0.4.0- Production on Thu Feb 5 13:00:27 2015Copyright (c) 1982, Oracle.  All rights reserved. Connected to:oracle Database 10g Enterprise Edition Release 10.2.0.4.0-productionwith The partitioning, OLAP, Data Mini NG and Real application testing optionsexport done in Us7ascii character set and al16utf16 NCHAR character Setserver uses Al32utf8 Character Set (possible charset conversion) about to export specified tables via conventional Path ..... Exporting table                           testexp-00056:oracle error 1578 encounteredora-01578:oracle data block corrupted (file # 6, Block # Ora-01110:data file 6: '/U02/APP/ORADATA/PSDB/LIVAN_TBS01.DBF ' Export terminated successfully with warnings.

9. Use Dbms_repair.check_object to check for bad blocks

 sql> BEGIN 2 dbms_repair. Admin_tables (3 table_name = ' repair_table ', 4 table_type = dbms_repair.repair_table, 5 ACTION =&G T   Dbms_repair.create_action, 6 tablespace = ' Livan_tbs ');  7 END; 8/pl/sql procedure successfully completed.   Sql> set serveroutput on sql> DECLARE 2 num_corrupt INT;   3 BEGIN 4 Num_corrupt: = 0; 5 Dbms_repair. Check_object (6 schema_name = ' Livan ', 7 object_name = ' TEST ', 8 repair_table_name = ' repair_t  ABLE ', 9 corrupt_count = num_corrupt); Ten dbms_output. Put_Line (' number corrupt: ' | |  To_char (Num_corrupt)); One END; 12/number Corrupt:1pl/sql procedure successfully completed. Sql> Select Relative_file_id,block_id,corrupt_type,object_name 2 from repair_table; relative_file_id block_id corrupt_type object_name--------------------------------------------------------------- -----6 6148 TEST 

10. Use the Analyze command to check for bad blocks

Sql> Analyze table test Validate structure Cascade online;analyze table test Validate structure Cascade Online*error at Line 1:ora-01578:oracle data block corrupted (file # 6, Block #) Ora-01110:data file 6: '/u02/app/oradata/psdb/livan_ TBS01.DBF '


11. Use bbed commands verify check for bad blocks

Bbed> Verify dba 6,12dbverify-verification startingfile =/u02/app/oradata/psdb/livan_tbs01.dbfblock = 12Block Corruptcorrupt block relative dba:0x0180000c (file 0, block) bad check value found during Verificationdata in bad block : Type:6 format:2 rdba:0x0180000c last change scn:0x0000.0007d460 seq:0x5 flg:0x06 spare1:0x0 spare2:0x0 spare3:0 X0 consistency value in tail:0xd4600605 check value in block HEADER:0X4D5C computed block Checksum:0x1607dbverify-ver Ification completetotal Blocks examined         : 1Total Blocks processed (data): 0Total Blocks failing   (data): 0Total B Locks processed (Index): 0Total Blocks failing   (index): 0Total Blocks Empty            : 0Total Blocks Marked corrupt   : 1 Total Blocks influx           : 0

Reference: Zhang Xiaoming << oracle rac>>
http://blog.csdn.net/tianlesoftware/article/details/5006580
http://blog.itpub.net/8494287/viewspace-1357457/
http://blog.csdn.net/haiross/article/details/15340489
Http://blog.sina.com.cn/s/blog_a57562c801015pzr.html

Simulating Oracle database bad blocks using bbed

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.