手工完全恢复(不可转储)

实验环境:red hat 5.8

oracle环境:11.2.0.3

实验情况:新建的表空间,来不及备份,就已经损坏的情况下。

新建的表空间,没有备份,无法转储,只能重建数据文件

1、查看一下现有的数据文件位置。

sys@TEST0910> select file#,name from v$datafile;
     FILE# NAME
---------- --------------------------------------------------
         1 /u01/app/oracle/oradata/test0910/system01.dbf
         2 /u01/app/oracle/oradata/test0910/sysaux01.dbf
         3 /u01/app/oracle/oradata/test0910/undotbs01.dbf
         4 /u01/app/oracle/oradata/test0910/users01.dbf
         5 /u01/app/oracle/oradata/test0910/example01.dbf
         6 /u01/app/oracle/oradata/test0910/testtb.dbf
6 rows selected.

2、新建一个表空间和一个数据表。

sys@TEST0910> create tablespace lxtbs datafile '/u01/app/oracle/oradata/test0910/lxtb01.dbf' size 20m;
Tablespace created.
在新建的表空间中新建一个表。
sys@TEST0910> create table scott.lxtb tablespace lxtbs as select * from scott.emp;
Table created.

3、插入三次数据,分别为提交归档,提交不归档,不提交不归档。

1.提交归档

sys@TEST0910> insert into scott.lxtb select * from scott.emp;
14 rows created.
sys@TEST0910> commit;
Commit complete.
sys@TEST0910> alter system archive log current;
System altered.
sys@TEST0910> select count(*) from scott.lxtb;
  COUNT(*)
----------
        28

2.提交不归档

sys@TEST0910> insert into scott.lxtb select * from scott.emp;
14 rows created.
sys@TEST0910>  commit;
Commit complete.
sys@TEST0910> select count(*) from scott.lxtb;
  COUNT(*)
----------
        42

3.不提交,不归档

sys@TEST0910> insert into scott.lxtb select * from scott.emp;
14 rows created.
sys@TEST0910> select count(*) from scott.lxtb;
  COUNT(*)
----------
        56

4、模拟断电。

sys@TEST0910> shutdown abort;
ORACLE instance shut down.

5、删除新建的表空间上的数据文件

[oracle@rtest ~]$ rm /u01/app/oracle/oradata/test0910/lxtb01.dbf
[oracle@rtest ~]$ ls /u01/app/oracle/oradata/test0910/lxtb01.dbf
ls: /u01/app/oracle/oradata/test0910/lxtb01.dbf: No such file or directory

6、起库,报错,查询损坏的数据文件

sys@TEST0910> startup
ORACLE instance started.
Total System Global Area 2505338880 bytes
Fixed Size                  2230952 bytes
Variable Size             587203928 bytes
Database Buffers         1895825408 bytes
Redo Buffers               20078592 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/u01/app/oracle/oradata/test0910/lxtb01.dbf'
查询哪个是坏的,这个数据文件没有备份。
sys@TEST0910> select file#,error from v$recover_file;
     FILE# ERROR
---------- -----------------------------------------------------------------
         7 FILE NOT FOUND

7、可先使用高可用模式先开库

sys@TEST0910> alter database datafile 7 offline;
Database altered.
sys@TEST0910> alter database open;
Database altered.

8、利用日志文件来恢复数据文件

新建一个空白的文件,用日志来恢复。这个就相当于转储。
sys@TEST0910> alter database create datafile '/u01/app/oracle/oradata/test0910/lxtb01.dbf';
Database altered.
sys@TEST0910> alter database datafile 7 online;
Database altered.
sys@TEST0910> select count(*) from scott.lxtb;
  COUNT(*)
----------
        42
原文地址:https://www.cnblogs.com/hzcya1995/p/13317211.html