最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
oracle中RMAN备份和检查逻辑坏块
时间:2022-06-29 09:39:04 编辑:袖梨 来源:一聚教程网
1. RMAN备份时是默认检查物理坏块。
2. 如果要检查逻辑坏块,可以用如下语句:
$ rman target /
RMAN> backup check logical validate database;
注上述语句,只是检查,不会备份的。
3. 如果要在备份的同时,进行逻辑坏块检查,可以用:
$ rman target /
RMAN> backup check logical database;
4.如果发现坏逻辑如何处理,下面补充一篇教程。
利用RMAN检测数据库坏块的脚本
虽然我们也可以通过dbv(db file verify)工具做到对单个数据文件的坏块检测,但是直接使用RMAN的”backup validate check logical database;”结合V$DATABASE_BLOCK_CORRUPTION视图要方便地多。
1) $ rman target / nocatalog
2) 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;
}
3) select * from V$DATABASE_BLOCK_CORRUPTION ;
REM www.askmaclean.com & www.askmaclean.com
4) If V$DATABASE_BLOCK_CORRUPTION contains rows please run this query to
find the objects that contains the corrupted blocks:
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 - 1, c.block# + c.blocks - 1) corr_end_block#,
least(e.block_id + e.blocks - 1, c.block# + c.blocks - 1) -
greatest(e.block_id, c.block#) + 1 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 - 1
AND e.block_id + e.blocks - 1 >= 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#,
1 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 - 1
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 - 1, c.block# + c.blocks - 1) corr_end_block#,
least(f.block_id + f.blocks - 1, c.block# + c.blocks - 1) -
greatest(f.block_id, c.block#) + 1 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 - 1
AND f.block_id + f.blocks - 1 >= 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 - 1;
补充:
启动 backup 于 28-11月-04
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 正在启动 full 数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
输入数据文件 fno=00028 name=E:ORACLEORADATAORABD02TS_TEST01.DBF
通道 ORA_DISK_1: 正在启动段 1 于 28-11月-04
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 11/28/2004 15:45:
51
ORA-19566: 超出损坏块限制 0 (文件 E:ORACLEORADATAORABD02TS_TEST01.DBF)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
扫描数据库的物理错误和逻辑错误
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
RMAN> backup validate datafile 28;
启动 backup 于 28-11月-04
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 正在启动 full 数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
输入数据文件 fno=00028 name=E:ORACLEORADATAORABD02TS_TEST01.DBF
通道 ORA_DISK_1: 备份集已完成, 经过时间:00:00:01
完成 backup 于 28-11月-04
注意:在rman validate操作期间会生成一些文本,看起来像是创建了一个备份集
但只是一个扫描错误的操作,在rman操作期间不会生成任何备份文件片
RMAN>
SQL> select * from V$BACKUP_CORRUPTION;
RECID STAMP SET_STAMP SET_COUNT PIECE# FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# MARKED
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------------
1 543426383 543426382 31 1 28 20 1 0 YES FRACTURED
已用时间: 00: 00: 00.00
SQL> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
---------- ---------- ---------- ------------------ ------------------
28 20 1 0 FRACTURED
已用时间: 00: 00: 00.00
SQL>
先看一下坏块是在表上还是索引上吧。
SELECT segment_name,segment_type,extent_id,block_id, blocks
from dba_extents t
where file_id = 6
AND 187 between block_id and (block_id + blocks - 1) ;
运气好,在索引上的话,直接重建就好了
例如:
我的数据库出现ORA-01578错误:数据块损坏(文件号8,块号36385)
用以下语句查询:
SELECT segment_name,segment_type FROM dba_extents WHERE file_id=8 AND 36385 BETWEEN block_id AND block_id + blocks -1;
结果为:
segment_name segment_type
----------------------- ------------------------
PK_KC03 INDEX
有的文章介绍说如果segment_type为INDEX的话,只要删除该索引再重建即可
使用:
alter index pk_kc03 rebuild nologging;
or
alter index pk_kc03 rebuild
dbms_repair.skip_corrupt_blocks过程设置表在读取数据时,跳过坏块
————————-——————————————————————————————————
四月 16 16:30:19 ur_bak01: NetWorker savegroup: (alert) urmdborafull completed, total 2 client(s), 0 Hostname(s) Unresolved, 1 Failed, 1 Succeeded. (ur_mdb01 Failed)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on t2 channel at 03/20/2009 13:49:09
ORA-19566: exceeded limit of 0 corrupt blocks for file /dev/vg_mdb02/rdata_2g_050
ORA-000060: Deadlock detected. More info in file /oracle/app/oracle/admin/uradt/udump/uradt_ora_3035.trc.
***
Corrupt block relative dba: 0x1a43d4e3 (file 105, block 251107)
Fractured block found during backing up datafile
Data in bad block -
type: 0 format: 0 rdba: 0x00000000
last change scn: 0x0000.00000000 seq: 0x0 flg: 0x00
consistency value in tail: 0x00000000
check value in block header: 0x0, block checksum disabled
spare1: 0x0, spare2: 0x0, spare3: 0x0
***
Reread of blocknum=251107, file=/dev/vg_mdb02/rdata_2g_050. found same corrupt data
Thu Apr 16 16:31:04 2009
用dbv检查发现有至少有45个坏块:
[oracle@ur_mdb01 /oracle$]dbv file=/dev/vg_mdb02/rdata_2g_050 BLOCKSIZE=8192
DBVERIFY: Release 9.2.0.6.0 - Production on Mon Apr 20 09:55:07 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
DBVERIFY - Verification starting : FILE = /dev/vg_mdb02/rdata_2g_050
Page 251107 is influx - most likely media corrupt
***
Corrupt block relative dba: 0x1a43d4e3 (file 105, block 251107)
Fractured block found during dbv:
Data in bad block -
type: 0 format: 0 rdba: 0x00000000
last change scn: 0x0000.00000000 seq: 0x0 flg: 0x00
consistency value in tail: 0x00000000
check value in block header: 0x0, block checksum disabled
spare1: 0x0, spare2: 0x0, spare3: 0x0
***
Page 251108 is marked corrupt
***
Corrupt block relative dba: 0x1a43d4e4 (file 105, block 251108)
Bad header found during dbv:
Data in bad block -
type: 181 format: 6 rdba: 0x00000000
last change scn: 0x0000.00000000 seq: 0x0 flg: 0x00
consistency value in tail: 0x00000000
check value in block header: 0x0, block checksum disabled
spare1: 0x7, spare2: 0xc, spare3: 0x0
***
……
Corrupt block relative dba: 0x1a43d56f (file 105, block 251247)
Bad header found during dbv:
Data in bad block -
type: 65 format: 5 rdba: 0x527002c2
last change scn: 0x3131.02063033 seq: 0x30 flg: 0x31
consistency value in tail: 0x3635032d
check value in block header: 0x180, block checksum disabled
spare1: 0x50, spare2: 0x72, spare3: 0x430
***
DBVERIFY - Verification complete
Total Pages Examined : 262016
Total Pages Processed (Data) : 60240
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 568
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 201163
Total Pages Marked Corrupt : 45
Total Pages Influx : 11
Highest block SCN : 10816042273 (2.2226107681)
经检查,发现这些坏块上没有任何数据对象:
方法1.可以找到这个数据文件所在的表空间,这个表空间下的所有对象:如果都是表,可以对这些表都做一次全部扫描,发现没有报错。如果都是索引,可以都走一次iff,没有报错的话,说明对象都不在坏块上。
方法2.用
select * from dba_extents where file_id=坏块file_id
and 坏块block_id between block_id and block_id+blocks-1;
如果所有的坏块执行这个sql检查出来的结果都是返回0行,说明没有对象在坏块上。
我们用格式化的方式来清除这样的坏块:
--预估剩余空间大小:
SQL> select tablespace_name,file_id,sum(bytes)/1024/1024 size_m from dba_free_space
2 where file_id=105 group by tablespace_name,file_id;
TABLESPACE_NAME FILE_ID SIZE_M
------------------------------ ---------- ----------
LOG_P8 105 1643
SQL>
--创建一个表在这个表空间上,用于做数据块的格式化:
SQL> create table for_fix(n number,c varchar2(4000)) nologging tablespace LOG_P8;
Table created.
SQL>
SQL>
SQL>
--填充满这个表:
SQL> alter table for_fix allocate extent(datafile '/dev/vg_mdb02/rdata_2g_050' size 1643m);
Table altered.
SQL>
SQL> insert into for_fix select rownum,rpad('dedwedew',3900) from dba_objects;
7285 rows created.
SQL> /
7285 rows created.
SQL> /
……
SQL> insert into for_fix select * from for_fix where rownum<=1000000;
1000000 rows created.
Elapsed: 00:00:06.96
SQL> /
1000000 rows created.
Elapsed: 00:00:03.50
SQL> /
10000 rows created.
Elapsed: 00:00:14.03
……
SQL> insert into for_fix select * from for_fix where rownum<=50000;
50000 rows created.
Elapsed: 00:00:39.28
SQL>
SQL>
……
SQL> insert into for_fix select * from for_fix where rownum<=1;
1 row created.
Elapsed: 00:00:00.00
SQL> /
1 row created.
Elapsed: 00:00:00.00
SQL> /
1 row created.
Elapsed: 00:00:00.00
SQL> /
1 row created.
Elapsed: 00:00:00.00
SQL> /
1 row created.
Elapsed: 00:00:00.01
SQL> /
insert into for_fix select * from for_fix where rownum<=1
*
ERROR at line 1:
ORA-01653: unable to extend table SYS.FOR_FIX by 128 in tablespace LOG_P8
Elapsed: 00:00:00.00
SQL>
SQL>
SQL> commit;
Commit complete.
Elapsed: 00:00:00.07
SQL>
SQL>
--记住,这里一定要做checkpoint,将所有的数据刷新到数据文件,不然不能保证所有的坏块被格式化:
SQL> alter system checkpoint;
System altered.
Elapsed: 00:00:04.25
SQL> /
System altered.
Elapsed: 00:00:00.15
SQL> /
System altered.
Elapsed: 00:00:00.14
填充满这个表后,所以的块都被得到格式化,包括坏块也被格式化了。此时我们用dbv再次检查:
[oracle@ur_mdb01 /oracle$]
dbv file=/dev/vg_mdb02/rdata_2g_050 BLOCKSIZE=8192
DBVERIFY: Release 9.2.0.6.0 - Production on Mon Apr 20 13:30:43 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
DBVERIFY - Verification starting : FILE = /dev/vg_mdb02/rdata_2g_050
DBVERIFY - Verification complete
Total Pages Examined : 262016
Total Pages Processed (Data) : 260715
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 1181
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 120
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 10816271785 (2.2226337193)
[oracle@ur_mdb01 /oracle$]
坏块已经处理掉了,测试rman备份正常。
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21