如何使用 RMAN 识别数据库中损坏的段。
解决方法:
步骤1:识别坏块
执行下面的 RMAN 命令,使所有的坏块信息被记录在 v$database_block_corruption 视图中:
RMAN> backup validate check logical database;
注意:
这个命令只是检查数据库的坏块,而不会真正进行备份。从 11g 开始可以省略 backup 子句,而直接使用命令"validate check logical database"。
如果由于缺失文件导致命令失败,可以增加 'SKIP INACCESSIBLE' 子句来避免这个问题。
为了加快检查速度,可以设置 PARALLELISM 指定多个通道:
RMAN> configure device type disk parallelism 4;
RMAN> backup validate check logical database;
OR
RMAN> run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup validate check logical database;
}
输出
坏块信息会被记录在视图 V$DATABASE_BLOCK_CORRUPTION 中。11g RMAN 会生成一个 trace 文件,详细描述坏块信息:
RMAN VALIDATE 屏幕输出:
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6 FAILED 0 501 640 1950088
File Name: /Oracle/dbs/users.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 9 9
Index 0 0
Other 0 130
validate found one or more corrupt blocks
See trace file /oracle/log/diag/rdbms/orcl/orcl/trace/orcl_ora_28424.trc for details
Finished validate at <Date>
Trace 文件输出坏块信息,这个例子描述了 2 个坏块,一个物理坏块(file 6 block 9)和一个逻辑坏块(file 6 block 10):
Corrupt block relative dba: 0x01000009 (file 4, block 9)
Bad check value found during validation
Data in bad block:
type: 16 format: 2 rdba: 0x01000009
last change scn: 0x0000.00000000 seq: 0xff flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x000010ff
check value in block header: 0xb4e0
computed block checksum: 0xa800
Reread of blocknum=9, file=/oracle/dbs/users.dbf found same corrupt data
Block Checking: DBA = 25165834, Block Type = KTB-managed data block
data header at 0x2b2deb49e07c
kdbchk: fsbo(144) wrong, (hsz 78)
Error backing up file 6, block 10: logical corruption
坏块信息记录在视图 V$DATABASE_BLOCK_CORRUPTION 中:
SQL> select * from V$DATABASE_BLOCK_CORRUPTION;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
--------------- --------------- --------------- ------------------ ---------
6 10 1 8183236781662 LOGICAL
6 42 1 0 FRACTURED
6 34 2 0 CHECKSUM
6 50 1 8183236781952 LOGICAL
6 26 4 0 FRACTURED
5 rows selected.
注意:
•CHECK LOGICAL 选项既会检查物理坏块也会检查逻辑坏块。
• 当发现逻辑坏块,alert 日志会更新以下的信息:
Error backing up file <file#>, block <block#>: logical corruption
在 11g 会生成一个 trace 文件,描述坏块信息。
• 当发现物理坏块时,alert 日志也会更新下面的信息: