[转]RMAN检测数据库坏块

时间:2023-05-26 11:38:20

backup validate check logical database;

select * from v$database_block_corruption;

RMAN> backup validate check logical database;

Starting backup at -SEP-
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID= device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID= device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number= name=/u02/app/oradata/ORCL/system01.dbf
input datafile file number= name=/u02/app/oradata/ORCL/rlst01.dbf
input datafile file number= name=/u02/app/oradata/ORCL/mssm01.dbf
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number= name=/u02/app/oradata/ORCL/sysaux01.dbf
input datafile file number= name=/u02/app/oradata/ORCL/undotbs01.dbf
input datafile file number= name=/u02/app/oradata/ORCL/users01.dbf
channel ORA_DISK_2: backup set complete, elapsed time: ::
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/sysaux01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/undotbs01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/users01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_2: backup set complete, elapsed time: ::
List of Control File and SPFILE
===============================
File Type Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
Control File OK
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_2: backup set complete, elapsed time: ::
List of Control File and SPFILE
===============================
File Type Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
SPFILE OK
channel ORA_DISK_1: backup set complete, elapsed time: ::
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/system01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/mssm01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
OK
File Name: /u02/app/oradata/ORCL/rlst01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
Index
Other Finished backup at -SEP-

利用数据字典表查询是否有坏块

SQL> desc v$database_block_corruption
Name Null? Type
----------------------------------------- -------- ----------------------------
FILE# NUMBER
BLOCK# NUMBER
BLOCKS NUMBER
CORRUPTION_CHANGE# NUMBER
CORRUPTION_TYPE VARCHAR2() SQL> select * from v$database_block_corruption; no rows selected

如果存在坏块可使用以下脚本查询:

SELECT e.owner,
e.segment_type,
e.segment_name,
e.partition_name,
c.file#,
greatest(e.block_id, c.block#) corr_start_block#,
least(e.block_id + e.blocks - , c.block# + c.blocks - ) corr_end_block#,
least(e.block_id + e.blocks - , c.block# + c.blocks - ) -
greatest(e.block_id, c.block#) + blocks_corrupted,
null description
FROM dba_extents e, v$database_block_corruption c
WHERE e.file_id = c.file#
AND e.block_id <= c.block# + c.blocks -
AND e.block_id + e.blocks - >= c.block#
UNION
SELECT s.owner,
s.segment_type,
s.segment_name,
s.partition_name,
c.file#,
header_block corr_start_block#,
header_block corr_end_block#,
blocks_corrupted,
'Segment Header' description
FROM dba_segments s, v$database_block_corruption c
WHERE s.header_file = c.file#
AND s.header_block between c.block# and c.block# + c.blocks -
UNION
SELECT null owner,
null segment_type,
null segment_name,
null partition_name,
c.file#,
greatest(f.block_id, c.block#) corr_start_block#,
least(f.block_id + f.blocks - , c.block# + c.blocks - ) corr_end_block#,
least(f.block_id + f.blocks - , c.block# + c.blocks - ) -
greatest(f.block_id, c.block#) + blocks_corrupted,
'Free Block' description
FROM dba_free_space f, v$database_block_corruption c
WHERE f.file_id = c.file#
AND f.block_id <= c.block# + c.blocks -
AND f.block_id + f.blocks - >= c.block#
order by file#, corr_start_block#;
SELECT tablespace_name, segment_type, owner, segment_name
FROM dba_extents
WHERE file_id = &fileid
and &blockid between block_id AND block_id + blocks - ;

参考:http://www.cnblogs.com/macleanoracle/archive/2013/03/19/2968101.html