【Oracle坏块】坏块类型:NOLOGGING
一、模拟NOLOGGING
模拟环境参考文章【Oracle坏块】Oracle坏块介绍 & 坏块类型:ALL ZERO
模拟NOLOGGING
SQL> alter table test nologging; Table altered. SQL> insert /*+ append_values */ into test values(20001,'dd'); 1 row created. SQL> commit; Commit complete. SQL> alter system flush buffer_cache; System altered. SQL> select * from v$database_block_corruption; no rows selected SQL> select count(*) from test; COUNT(*) ---------- 20001
设置数据文件offline
SQL> alter database datafile 22 offline; Database altered.
用之前备份的数据文件恢复
RMAN> restore datafile 22; Starting restore at 02-AUG-21 using channel ORA_DISK_1 creating datafile file number=22 name=/u01/app/oracle/oradata/T1/pdb/test.dbf restore not done; all files read only, offline, excluded, or already restored Finished restore at 02-AUG-21 RMAN> recover datafile 22; Starting recover at 02-AUG-21 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 02-AUG-21
设置数据文件在线online
SQL> alter database datafile 22 online; Database altered. SQL> select count(*) from test; select count(*) from test * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 22, block # 177) ORA-01110: data file 22: '/u01/app/oracle/oradata/T1/pdb/test.dbf' ORA-26040: Data block was loaded using the NOLOGGING option
查看报错
SQL> select * from v$database_block_corruption; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO --------------- --------------- --------------- ------------------ --------- 22 131 1 3246537 NOLOGGING
二、恢复方法
NOLOGGING操作引起的坏块是不能恢复的,比如“Media Recovery”或“RMAN Blockrecover“都无法修复这种块
可行的方法是,在NOLOGGING操作之后立刻备份对应的数据文件,对于除了索引以外的其它类型的段,为了修复这个问题,可以通过导出文件(exp/expdp)或者其他数据源来进行恢复
如果没有备份,可以采用下面的方法重建对象,找到块所在的对象:
- 如果是索引,重新创建(drop/create)索引
- 如果是表,使用DBMS_REPAIR包或者CTAS复制方式跳过坏块(丢数据)
- 如果是表中的LOB列对应的LOB段,参考[Note 293515.1]
- 如果错误出现在物理STANDBY数据库,从主库恢复被影响的数据文件(只有当主库没有这个问题的情况下)