oracle壞塊問題的處理


 

一、背景

今天有用戶反映數據庫連不上了,查看日志發現有數據庫壞塊。

查看數據庫日志,有如下報錯:

ORA-01578: ORACLE , 93642)
ORA-01110: 1: '/oracle/app/orcldata/orcl/system01.dbf'
ORACLE Instance orcl (pid = 13) - Error 1578 encountered while recovering transaction (89, 2) on object 226.
Errors in file /oracle/app/diag/rdbms/orcl/orcl/trace/orcl_smon_3345.trc:

 

二、查詢壞塊方法

(1)通過trc文件查看

查看上面err的具體trc:

如上,壞塊信息很明確。

(2)簡單語句查詢

select * from v$database_block_corruption;

(3)DBV查看壞塊

dbv file=system01.dbf  blocksize=8192

有一個壞塊

 

 

三、壞塊的處理

根據文件號和塊號查出損壞的是對象,表還是LOB segment

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

其中1是文件號,93642是block號

(1)索引損壞

#如果被損壞的塊是索引,通常可以通過索引重建來解決

alter index indexname rebuild;

(1)表損壞

 segment_type為table

#可以使用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;

alter index indexname rebuild;

alter session SET EVENTS '10231 trace name context off';

注:根據表名查看索引名

SELECT * FROM ALL_INDEXES WHERE TABLE_NAME='IDL_CHAR$';

使用rman工具恢復:

---使用rman工具的blockrecover 

blockrecover datafile xx block xx;--修復單個壞塊
blockrecover corruption list;--修復全部壞塊

  

 

(3)LOB segment損壞

如果損壞的是LOB segment

#先找出segment信息
select owner, segment_name, segment_type from dba_extents where file_id = 38 and 295563 between block_id and block_id + blocks - 1;

#輸出如下
owner=HGHIS
segment_name=SYS_LOB0000119493C00006$$
segment_type=LOBSEGMENT

#找到表明和LOB字段
select table_name, column_name from dba_lobs where segment_name = 'SYS_LOB0000119493C00006$$' and owner = 'HGHIS';

#輸出如下
table_name = EMR_CASE
column_name = WORD

#找到壞塊的bad rowid,使用以下plsql腳本
create table bad_rows (row_id ROWID,oracle_error_code number);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM