20240308-Oracle数据库处理坏块问题常用命令

在这里插入图片描述

1.通过DBV 检查文件是否有坏块

例如:检查 cjc_index01.dbf 文件

dbv file='/oradata/nc/cjc_index01.dbf'

2.检查坏块所属段类型

例如:file_id=6(cjc_index01.dbf),block=459202

select tablespace_name, segment_type, owner, segment_name
  from dba_extents
 where file_id = 6
   and 459202  between block_id and block_id + blocks - 1;

3.rman恢复坏块

恢复方式:基于数据块的Rman 恢复
检查datafile=6的所有坏块

检查坏块位置

RMAN>backup validate datafile 6;

验证坏块

select FILE#,BLOCK#,BLOCKS,CORRUPTION_CHANGE#,CORRUPTION_TYPE from v$database_block_corruption where file#=6;

修复坏块

RMAN>blockrecover datafile 6 block 459202 from backupset;

如果有多个坏块,可以用逗号分开,例如:

RMAN>blockrecover datafile 6 block 459202,643867,1963727;

4.如果没有RMAN备份
索引类型坏块,可以选择重建索引;
数据类型坏块,可以选择跳过坏块导出数据,重建表。
如果是通过exp备份不能直接备份出有坏块的表,需要设置内部事件

ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10';

通过expdp 备份可以直接跳过坏块;
也可以使用10231事件忽略坏块,然后使用CTAS方式重建表最后rename table,别忘记rebuild index,例如:

alter session SET EVENTS '10231 trace name context forever,level 10';
create table tab_new as select * from tab;
rename tab to tab_bak;
rename tab_new to new;
select 'alter index '||index_name||' rebuild;' from user_ind_columns where table_name='T1';
alter session SET EVENTS '10231 trace name context off';

###chenjuchao 20240308###
欢迎关注我的公众号《IT小Chen

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值