天天看點

oracle 修複壞塊,記一次Oracle壞塊修複過程

oracle 修複壞塊,記一次Oracle壞塊修複過程

昨天接備份同僚電話反應在進行RMAN冷備的過程中報如下錯,某個表空間備份失敗。RMAN-00571: ==================================

昨天接備份同僚電話反應在進行RMAN冷備的過程中報如下錯,某個表空間備份失敗。

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03009: failure of backup command on ch00 channel at 04/25/2015 22:02:30

ORA-19566: exceeded limit of 0 corrupt blocks for file +DATA/dbrac/datafile/tbs_11.11.435678937

經過分析發現壞塊導緻,且壞塊不屬于任何對象(空塊),,以下是本次壞塊修複步驟:

1、查找壞塊

1)使用RMAN查找壞塊

驗證整個資料庫:

Rman> backup validate check logical database ;

注:當資料庫版本低于11g且非歸檔模式,以上指令必須在資料庫處于mounted狀态執行

驗證單個datafile

Rman> backup validate check logical datafile 11 ;

而後執行以下SQL檢視壞塊:

SQL>Select * from v$database_block_corruption ;

例如:

validate.sh

#!/bin/bash

source /home/Oracle/.bash_profile

$ORACLE_HOME/bin/rman log=/home/oracle/users/validate.log < connect target /

Backup validate check logical datafile 11 ;

exit;

EOF

2)使用DBV查找壞塊:

dbv userid=system/system file='+DATA/dbrac/datafile/tbs_11.11.435678937' blocksize=32768

2、确認壞塊是否不屬于任何對象

select segment_name, segment_type, owner

from dba_extents

where file_id =

and between block_id

and block_id + blocks -1;

例如:

alter session force parallel query parallel 10;

select segment_name, segment_type, owner

from dba_extents

where file_id = 11

and 184959440 between block_id

and block_id + blocks -1;

3、确認塊在 dba_free_space存在

Select * from dba_free_space where file_id=

and between block_id and block_id + blocks -1;

例如:

Select * from dba_free_space where file_id= 11 and 184959440 between block_id and block_id + blocks -1;

4、建立表

create table s (

n number,

c varchar2(4000)

) nologging tablespace pctfree 99;

例如:

create table users.s (

n number,

c varchar2(4000)

) nologging tablespace TBS_11 pctfree 99;

select segment_name,tablespace_name from dba_segments

where segment_name='S' ;

Select table_name,tablespace_name from dba_tables where table_name='S' ;

5、建立觸發器

CREATE OR REPLACE TRIGGER corrupt_trigger

AFTER INSERT ON users.s

REFERENCING OLD AS p_old NEW AS new_p

FOR EACH ROW

DECLARE

corrupt EXCEPTION;

BEGIN

IF (dbms_rowid.rowid_block_number(:new_p.rowid)=&blocknumber)

and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=&filenumber) THEN

RAISE corrupt;

END IF;

EXCEPTION

WHEN corrupt THEN

RAISE_APPLICATION_ERROR( -20000, 'Corrupt block has been formatted');

END;

/

6、配置設定空間建立在有壞塊的datafile上的表

注:

i)因為ASSM會自動确定下一個區段的大小,是以在ASSM的表空間上,需要建立多個表及

不斷的配置設定空間給這些表,直到壞塊被配置設定至其中一個對象。

ii)設定datafile的AUTOEXTEND為OFF

1)查找壞塊的extent size

Select BYTES from dba_free_space where file_id=and between

block_id and block_id + blocks -1;

例如:

alter database datafile '+DATA/dbrac/datafile/tbs_11.11.435678937' autoextend off;

SQL> Select BYTES from dba_free_space where file_id=11 and 184959440 between

2 block_id and block_id + blocks -1;

BYTES

----------

29360128

2)不斷allocate直到壞塊是S表的一部分

如果步驟1輸出結果是64K,執行以下SQL:

alter table users.s

allocate extent (DATAFILE '+DATA/dbrac/datafile/tbs_11.11.435678937' SIZE 64K);

如果大于64K使用以下

BEGIN

for i in 1..1000000 loop

EXECUTE IMMEDIATE 'alter table users.s allocate extent (DATAFILE '||'''+DATA/dbrac/datafile/tbs_11.11.435678937'''||'SIZE 64K) ';

end loop;

end ;

/

oracle 修複壞塊,記一次Oracle壞塊修複過程
oracle 修複壞塊,記一次Oracle壞塊修複過程

本條技術文章來源于網際網路,如果無意侵犯您的權益請點選此處回報版權投訴

本文系統來源:php中文網