Use RMAN to backup and restore the database (10)-repair damaged data blocks

Use RMAN to backup and restore the database (10)-repair damaged data blocks

If a data file is normal, but some data blocks in the data file are damaged, you can use RMAN to repair it.

1. Simulated data block damage

1. Create a new tablespace data03

Create a new table space data03 with a file size of 5M.

SQL> create tablespace data03 datafile '/usr/local/oradata/orcl/data03.dbf' size 2m;

Tablespace created.

Elapsed: 00:00:00.40
SQL> select name from v$datafile;

NAME
-----------------------------------------------------------------------------------
/usr/local/oradata/orcl/system01.dbf
/usr/local/oradata/orcl/sysaux01.dbf
/usr/local/oradata/orcl/undotbs01.dbf
/usr/local/oradata/orcl/users01.dbf
/usr/local/oradata/orcl/data01.dbf
/usr/local/oradata/orcl/data02.dbf
/usr/local/oradata/orcl/data03.dbf

2. Create a table in the tablespace data03

Create a scott.t_emp table in the table space and add data to fill the entire table space.

SQL> create table scott.t_emp tablespace data03 as select * from scott.e02 where rownum<20000;
Table created.

3. Use RMAN to backup table space

RMAN> recover tablespace data03;

Starting recover at 2020-04-12 14:45:55
using channel ORA_DISK_1
using channel ORA_DISK_2

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 2020-04-12 14:45:56

RMAN> backup tablespace data03 format '/home/oracle/rmanbak/data03.bak';

Starting backup at 2020-04-12 14:47:50
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/usr/local/oradata/orcl/data03.dbf
channel ORA_DISK_1: starting piece 1 at 2020-04-12 14:47:51
channel ORA_DISK_1: finished piece 1 at 2020-04-12 14:47:52
piece handle=/home/oracle/rmanbak/data03.bak tag=TAG20200412T144751 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-04-12 14:47:52

4. Set the tablespace data03 to offline

SQL> alter tablespace data03 offline;

Tablespace altered.

5. Edit the data03.dbf file with vim and save it.

[oracle@wgx orcl]$ vim -b data03.dbf

6. Set the tablespace data03 to online

SQL> alter tablespace data03 online;
Tablespace altered.

Two, view the data of the t_emp table

Prompt that there is a bad data block, the result is as follows:

SQL> select count(*) from scott.t_emp;
select count(*) from scott.t_emp
                           *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 7, block # 158)
ORA-01110: data file 7: '/usr/local/oradata/orcl/data03.dbf'

Three, use RMAN to repair damaged data blocks

1. View the information of the damaged data block

As you can see, two data blocks are damaged.

SQL> select file#,block# from v$database_block_corruption;

     FILE#     BLOCK#
---------- ----------
	 7	  163
	 7	  158

Elapsed: 00:00:00.04

2. Use RMAN to repair damaged data blocks

RMAN> blockrecover corruption list;

Starting recover at 2020-04-12 14:53:35
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=133 device type=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00007
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/data03.bak
channel ORA_DISK_1: piece handle=/home/oracle/rmanbak/data03.bak tag=TAG20200412T144751
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 2020-04-12 14:53:40

Four, view the data of the t_emp table

SQL> select count(*) from scott.t_emp;

  COUNT(*)
----------
     19999

Five, view the information of the damaged data block

SQL> select file#,block# from v$database_block_corruption;

no rows selected

The repair is successful!

Guess you like

Origin blog.csdn.net/weixin_44377973/article/details/105474057