欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

ORACLE模拟一个数据文件坏块并使用RMAN备份来恢复

程序员文章站 2023-12-26 18:39:15
...

1.创建一个实验用的表空间并在此表空间上创建表 create tablespace blocktest datafile '/u01/oradata/bys1/blocktest.dbf' size 1m; col name for a40 select file#,name from v$datafile; FILE# NAME ---------- ----------------------------------------


1.创建一个实验用的表空间并在此表空间上创建表

create tablespace blocktest datafile '/u01/oradata/bys1/blocktest.dbf' size 1m;

col name for a40
select file#,name from v$datafile;
FILE# NAME
---------- ----------------------------------------
1 /u01/oradata/bys1/system01.dbf
2 /u01/oradata/bys1/sysaux01.dbf
3 /u01/oradata/bys1/undotbs01.dbf
4 /u01/oradata/bys1/users01.dbf
5 /u01/oradata/bys1/example01.dbf
6 /u01/oradata/bys1/blocktest.dbf

BYS@bys1>create table test9 tablespace blocktest as select * from scott.emp;
Table created.
BYS@bys1>select count(*) from test9;
COUNT(*)
----------
14

2.使用RMAN对数据库进行备份,这里为了快速实验我只备份了准备制造坏块的数据文件。

[oracle@bys001 ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Sep 13 13:28:36 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: BYS1 (DBID=3957527513)

RMAN> backup datafile 6;

Starting backup at 13-SEP-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/oradata/bys1/blocktest.dbf
channel ORA_DISK_1: starting piece 1 at 13-SEP-13
channel ORA_DISK_1: finished piece 1 at 13-SEP-13
piece handle=/u01/flash_recovery_area/BYS1/backupset/2013_09_13/o1_mf_nnndf_TAG20130913T150457_935g8s7w_.bkp tag=TAG20130913T150457 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 13-SEP-13

RMAN> list backupset 7;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7 Full 1.02M DISK 00:00:00 13-SEP-13
BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20130913T150457
Piece Name: /u01/flash_recovery_area/BYS1/backupset/2013_09_13/o1_mf_nnndf_TAG20130913T150457_935g8s7w_.bkp
List of Datafiles in backup set 7
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1910363 13-SEP-13 /u01/oradata/bys1/blocktest.dbf

3.模拟产生一个坏块:我这里使用了VI来删除数据文件中一些内容方法

[oracle@bys001 bys1]$ vi blocktest.dbf 打开后都是乱码,随便删除点中间的数据就可以,有时候 需要多次删除才会有坏块。我第一次实验一下就制造出坏块,后来都是通过多次才行。然后进入数据库查询建立在blocktest.表空间上的TEST9表,报错并给出了坏块的提示:文件号是6,坏块是10:

[oracle@bys001 bys1]$ sqlplus bys/bys
BYS@bys1>select * from test9;
select * from test9
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 10)
ORA-01110: data file 6: '/u01/oradata/bys1/blocktest.dbf'


4.进入RMAN,修复坏块

《《《可选:--我未做

RMAN> backup validate datafile 6; 这条命令是对文件做一次校验,也可以发现坏块。
然后从SQLPLUS中查询:select * from v$database_block_corruption;

直接使用RMAN指定恢复的文件及BLOCK号》》》

执行以下 命令来修复坏块:

RMAN> blockrecover datafile 6 block 10 from backupset;
RMAN> exit

6.在SQLPLUS中查询表

BYS@bys1>select count(*) from test9;
COUNT(*)
----------
14

上一篇:

下一篇: