模拟坏块以后,准备学习检测坏块
1使用DBV工具检测oracle数据文件产生的坏块
dbverify工具的主要目的是为了检查数据文件的物理结构,包括数据文件是否损坏,是否存在逻辑坏块,以及数据文件中包含何种类型的数据。
DBVERIFY工具可以验证ONLINE或OFFLINE的数据文件。不管数据库是否打开,都可以访问数据文件。
注意:
(1)对于DBVERIFY工具,高版本可以自动识别低版本数据库,比如11g的dbv访问9i的数据库,但是低版本的dbv访问高版本会报如下之类的错误:
DBVERIFY-验证正在开始: FILE =e:/oracle/oradata/Dave/test01.dbf
汇入的页1 -可能是介质损坏
2)查看数据坏块所在数据文件号及块号可以对表进行一次全表扫描,如:
select count(*) from tablename;
如果有坏块, 在扫描的时候就会报错。
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/oradata/orcl/system01.dbf
/home/oracle/oradata/orcl/undotbs01.dbf
/home/oracle/oradata/orcl/sysaux01.dbf
/home/oracle/oradata/orcl/users01.dbf
/home/oracle/oradata/orcl/test101.dat
/home/oracle/oradata/orcl/block.dat
6 rows selected.
SQL> !
oracle@AS5TEST_/home/oracle$ dbv file=/home/oracle/oradata/orcl/test101.dat
DBVERIFY: Release 10.2.0.4.0 - Production on Mon Nov 19 23:54:48 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /home/oracle/oradata/orcl/test101.dat
Page 14 is influx - most likely media corrupt
Corrupt block relative dba: 0x0140000e (file 5, block 14)
Fractured block found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x0140000e
last change scn: 0x0000.00070b81 seq: 0xd flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x3534060d
check value in block header: 0xa4da
computed block checksum: 0x0
DBVERIFY - Verification complete
Total Pages Examined : 1280
Total Pages Processed (Data) : 4
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 1
Total Pages Failing (Index): 0
Total Pages Processed (Other): 14
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 1260
Total Pages Marked Corrupt : 1
Total Pages Influx : 1
Highest block SCN : 461702 (0.461702)
oracle@AS5TEST_/home/oracle$
可以发现Pages Marked Corrupt 数量为1,
可以根据dbv提示的位置进行查找坏块位置的信息
SQL> select owner,segment_name,segment_type from dba_extents where file_id=5 and 14 between block_id and block_id+blocks-1;
OWNER
------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
SEGMENT_TYPE
------------------
DW
TESTTP
TABLE
发现时表的块损坏
2使用exp导出遇见坏块会报错
oracle@AS5TEST_/home/oracle$ exp dw/dw file=/home/oracle/2.dmp owner=dw;
Export: Release 10.2.0.4.0 - Production on Tue Nov 20 00:25:19 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. exporting pre-schema procedural objects and actions
……
. about to export DW's tables via Conventional Path ...
. . exporting table TESTTP
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 5, block # 14)
ORA-01110: data file 5: '/home/oracle/oradata/orcl/test101.dat'
. . exporting table TESTTTP2 11 rows exported
. exporting synonyms
. exporting views
……
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully with warnings.
3使用RMAN备份数据文件
备份数据文件失败
RMAN> backup datafile 5;
Starting backup at 20-NOV-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=313 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/home/oracle/oradata/orcl/test101.dat
channel ORA_DISK_1: starting piece 1 at 20-NOV-12
RMAN-00571: ================================================
RMAN-00569: =====ERROR MESSAGE STACK FOLLOWS =============
RMAN-00571: ================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 11/20/2012 00:27:22
ORA-19566: exceeded limit of 0 corrupt blocks for file /home/oracle/oradata/orcl/test101.dat
4使用DBMS_REPAIR检查坏块
REPAIR_TABLE用来记录错误检查结果
ORPHAN_KEY_TABLE用来记录表坏块中记录在索引中对应键值
--建立测试用表空间
create tablespace block datafile '/home/oracle/oradata/orcl/block.dat'size 5M;
--建立REPAIR_TABLE表
BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'REPAIR_TABLE',
TABLE_TYPE => dbms_repair.repair_table,
ACTION => dbms_repair.create_action,
TABLESPACE => 'block');
END;
/
--建立ORPHAN_KEY_TABLE表
BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'ORPHAN_KEY_TABLE',
TABLE_TYPE => dbms_repair.orphan_table,
ACTION => dbms_repair.create_action,
TABLESPACE => 'block');
END;
/
--这两个表的删除可以通过下列存储过程完成
BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'REPAIR_TABLE',
TABLE_TYPE => dbms_repair.repair_table,
ACTION => dbms_repair.drop_action);
END;
/
BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'ORPHAN_KEY_TABLE',
TABLE_TYPE => dbms_repair.orphan_table,
ACTION => dbms_repair.drop_action);
END;
/
使用CHECK_OBJECT过程检测坏块。
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 num_corrupt INT;
3 BEGIN
4 num_corrupt := 0;
5 DBMS_REPAIR.CHECK_OBJECT (
6 SCHEMA_NAME => 'DW',
7 OBJECT_NAME => 'TESTTP',
8 REPAIR_TABLE_NAME => 'REPAIR_TABLE',
9 CORRUPT_COUNT => num_corrupt);
10 DBMS_OUTPUT.PUT_LINE('number corrupt: ' || TO_CHAR (num_corrupt));
11 END;
12 /
number corrupt: 1
发现一个坏块
--查看坏块信息
SELECT OBJECT_NAME, BLOCK_ID, CORRUPT_TYPE, MARKED_CORRUPT,
CORRUPT_DESCRIPTION, REPAIR_DESCRIPTION
FROM REPAIR_TABLE;