日期:2014-05-16  浏览次数:20385 次

Oracle恢复实验(三)

环境:Oracle10g、Red Hat 4,Oracle运行在归档模式。

场景:恢复未备份的数据文件。

具体步骤:
1、新建表空间testts,并建个表,插入些数据
SQL> create tablespace testts datafile '/home/oracle/oracle/product/oradata/orcl/testts01.dbf' size 10m;

Tablespace created.

SQL> create table testTab tablespace testts
  2  as select * from scott.emp;

Table created.

SQL> select count(*) from testTab;

  COUNT(*)
----------
        14

SQL> commit;

Commit complete.

2、关库、删除数据文件,模拟数据文件损坏,注意没有备份哟
SQL> shutdown abort

SQL> !rm -f /home/oracle/oracle/product/oradata/orcl/testts01.dbf

3、尝试打开数据库
SQL> startup
ORACLE instance started.

Total System Global Area  130023424 bytes
Fixed Size                  1218100 bytes
Variable Size              67111372 bytes
Database Buffers           58720256 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/home/oracle/oracle/product/oradata/orcl/testts01.dbf'
会提示数据文件无法找到。

5、重建数据文件,尝试打开数据库。
SQL> alter database create datafile '/home/oracle/oracle/product/oradata/orcl/testts01.dbf';

Database altered.

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/home/oracle/oracle/product/oradata/orcl/testts01.dbf'
此时数据文件是个空的,当然需要介质恢复

6、介质恢复
SQL> recover database;
Media recovery complete.

7、打开数据库,查检数据是否恢复
SQL> alter database open;

Database altered.

SQL> select count(*) from testTab;

  COUNT(*)
----------
        14
全部数据都恢复回来了。