oracle坏块,教你手把手修复oracle坏块(一)!!!

 

首先,坏块分为物理坏块和逻辑坏块。前者通常是硬件的问题,后者是oracle本身内部的问题。

先给oracle数据库开启归档模式

SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /oracle/app/product/11.2.0/db_1/dbs/arch
Oldest online log sequence     6
Current log sequence           8
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  759943168 bytes
Fixed Size                  2257112 bytes
Variable Size             654315304 bytes
Database Buffers           96468992 bytes
Redo Buffers                6901760 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/app/product/11.2.0/db_1/dbs/arch
Oldest online log sequence     6
Next log sequence to archive   8
Current log sequence           8

 

创建坏块修复实验的表空间,用户和所需权限

--创建一个大小为1m的表空间

create tablespace test datafile '/oracle/app/oradata/xtts11g/test01.dbf' size 1m;

--创建test用户

create user test identified by test default tablespace test temporary tablespace temp profile DEFAULT;

--授予相关的测试权限

grant connect,dba,resource,unlimited tablespace to test;

创建表和模拟数据

SQL> conn test/test;   
Connected.
SQL> create table test tablespace test as select * from scott.emp;

Table created.

SQL> insert into test select * from test;

14 rows created.

SQL> /

28 rows created.

SQL> /

56 rows created.

SQL> /

112 rows created.

SQL> /

224 rows created.

SQL> /

448 rows created.

SQL> /

896 rows created.

SQL> /

1792 rows created.

SQL> /

3584 rows created.

SQL> /

7168 rows created.

SQL> /
insert into test select * from test
*
ERROR at line 1:
ORA-01653: unable to extend table TEST.TEST by 8 in tablespace TEST


SQL> select count(*) from test;

  COUNT(*)
----------
     14336

触发检查点,将数据写入到数据文件中

SQL> alter system checkpoint;

System altered.

 

进行模拟坏块前,先用rman进行备份

[oracle@mongodb ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Feb 20 13:46:55 2021

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

connected to target database: XTTS11G (DBID=1621650015)

RMAN> backup tablespace 'TEST' tag=zq;

Starting backup at 20-FEB-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=406 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/oracle/app/oradata/xtts11g/test01.dbf
input datafile file number=00006 name=/oracle/app/oradata/xtts11g/test02.dbf
channel ORA_DISK_1: starting piece 1 at 20-FEB-21
channel ORA_DISK_1: finished piece 1 at 20-FEB-21
piece handle=/oracle/app/product/11.2.0/db_1/dbs/01vnlmnq_1_1 tag=ZQ comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20-FEB-21

RMAN> 

关闭数据库,用bbed篡改数据文件

bbed安装方法

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

cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed

bbed的安装介质在我的资源分享中可以免费下载,linux和aix的都有 

使用bbed修改数据文件,人为制造坏块

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@mongodb ~]$ cd $ORACLE_HOME/rdbms/lib 
[oracle@mongodb lib]$ ls bbed
bbed
[oracle@mongodb lib]$ vi par.txt 
blocksize=8192
listfile=filelist.txt
mode=edit
[oracle@mongodb lib]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 22 13:54:47 2021

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select file#||chr(9)||name||chr(9)||bytes from v$datafile;

FILE#||CHR(9)||NAME||CHR(9)||BYTES
--------------------------------------------------------------------------------
1       /oracle/app/oradata/xtts11g/system01.dbf        796917760
2       /oracle/app/oradata/xtts11g/sysaux01.dbf        534773760
3       /oracle/app/oradata/xtts11g/undotbs01.dbf       89128960
4       /oracle/app/oradata/xtts11g/users01.dbf 5242880
5       /oracle/app/oradata/xtts11g/test01.dbf  1048576
6       /oracle/app/oradata/xtts11g/test02.dbf  106496

6 rows selected.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@mongodb lib]$ vi filelist.txt 
1 /oracle/app/oradata/xtts11g/system01.dbf 796917760
2 /oracle/app/oradata/xtts11g/sysaux01.dbf 534773760
3 /oracle/app/oradata/xtts11g/undotbs01.dbf 89128960
4 /oracle/app/oradata/xtts11g/users01.dbf 5242880
5 /oracle/app/oradata/xtts11g/test01.dbf 1048576
6 /oracle/app/oradata/xtts11g/test02.dbf 106496
选择5号数据文件
[oracle@mongodb lib]$ ./bbed parfile=par.txt password=blockedit

BBED: Release 2.0.0.0.0 - Limited Production on Mon Feb 22 13:56:20 2021

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

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

BBED> set dba 5,19
        DBA             0x01400013 (20971539 5,19)
破坏尾部8188偏移量
BBED> map
 File: /oracle/app/oradata/xtts11g/test01.dbf (5)
 Block: 19                                    Dba:0x01400013
------------------------------------------------------------
 KTB Data Block (Table/Cluster)

 struct kcbh, 20 bytes                      @0       

 struct ktbbh, 72 bytes                     @20      

 struct kdbh, 14 bytes                      @100     

 struct kdbt[1], 4 bytes                    @114     

 sb2 kdbr[170]                              @118     

 ub1 freespace[837]                         @458     

 ub1 rowdata[6893]                          @1295    

 ub4 tailchk                                @8188    

BBED> set offset 8188
        OFFSET          8188

BBED> m /x ff 8188
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
 File: /oracle/app/oradata/xtts11g/test01.dbf (5)
 Block: 19               Offsets: 8188 to 8191           Dba:0x01400013
------------------------------------------------------------------------
 ff06c348 

 <32 bytes per line>

BBED> sum apply
Check value for File 5, Block 19:
current = 0x084c, required = 0x084c

BBED> verify
DBVERIFY - Verification starting
FILE = /oracle/app/oradata/xtts11g/test01.dbf
BLOCK = 19

Block 19 is corrupt
Corrupt block relative dba: 0x01400013 (file 0, block 19)
Fractured block found during verification
Data in bad block:
 type: 6 format: 2 rdba: 0x01400013
 last change scn: 0x0000.001048c3 seq: 0x1 flg: 0x06
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x48c306ff
 check value in block header: 0x84c
 computed block checksum: 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           : 2
Message 531 not found;  product=RDBMS; facility=BBED

可以看到已经成功制造了坏块,现在使用dbv和查询再次验证下
[oracle@mongodb lib]$ dbv file=/oracle/app/oradata/xtts11g/test01.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Mon Feb 22 14:01:04 2021

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

DBVERIFY - Verification starting : FILE = /oracle/app/oradata/xtts11g/test01.dbf
Page 19 is influx - most likely media corrupt
Corrupt block relative dba: 0x01400013 (file 5, block 19)
Fractured block found during dbv: 
Data in bad block:
 type: 6 format: 2 rdba: 0x01400013
 last change scn: 0x0000.001048c3 seq: 0x1 flg: 0x06
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x48c306ff
 check value in block header: 0x84c
 computed block checksum: 0x0



DBVERIFY - Verification complete

Total Pages Examined         : 128
Total Pages Processed (Data) : 109
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 17
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 1
Total Pages Encrypted        : 0
Highest block SCN            : 1067203 (0.1067203)

SQL> startup
ORACLE instance started.

Total System Global Area  759943168 bytes
Fixed Size                  2257112 bytes
Variable Size             654315304 bytes
Database Buffers           96468992 bytes
Redo Buffers                6901760 bytes
Database mounted.
Database opened.
SQL> conn test/test;
Connected.
SQL> select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 19)
ORA-01110: data file 5: '/oracle/app/oradata/xtts11g/test01.dbf'

利用备份恢复坏块

[oracle@mongodb lib]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Feb 22 14:21:59 2021

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

connected to target database: XTTS11G (DBID=1621650015)

RMAN> blockrecover datafile 5 block 19;

Starting recover at 22-FEB-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=406 device type=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00005
channel ORA_DISK_1: reading from backup piece /oracle/app/product/11.2.0/db_1/dbs/06vnqvog_1_1
channel ORA_DISK_1: piece handle=/oracle/app/product/11.2.0/db_1/dbs/06vnqvog_1_1 tag=ZQ
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 22-FEB-21
[oracle@mongodb lib]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 22 14:25:30 2021

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn test/test;
Connected.
SQL> select count(*) from test;

  COUNT(*)
----------
     14336

至此,修复完成,当然这是有备份情况下的坏块修复,接下来我还会更新没有备份的时候的坏块处理方式,有兴趣的小伙伴可以关注一下博主,过几日继续更新,觉得文章有用的点个赞把!

 

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值