丢失已经归档了的日志文件恢复数据库时候,还算是相对简单的事情,只要把丢失
了的归档日志文件清空就可以了。然后直接打开数据库。以下是测试的过程:
----丢失已归档重做日志文件:
--查看测试表的原来的记录:
suxing@PROD>select * from t2;
EMPNO ENAME JOB SAL DEPTNO
---------- ---------- --------- ---------- ----------
7369 SMITH CLERK 800 20
7566 JONES MANAGER 2975 20
7788 SCOTT ANALYST 3000 20
7876 ADAMS CLERK 1100 20
7902 FORD ANALYST 3000 20
7777 SUSU CLERK 3000 20
--往测试表中再插入6条记录:
suxing@PROD>insert into t2
2 select * from t1 where deptno = 30;
6 rows created.
suxing@PROD>commit;
Commit complete.
--再次查看测试表的记录:
suxing@PROD>select * from t2;
EMPNO ENAME JOB SAL DEPTNO
---------- ---------- --------- ---------- ----------
7369 SMITH CLERK 800 20
7566 JONES MANAGER 2975 20
7788 SCOTT ANALYST 3000 20
7876 ADAMS CLERK 1100 20
7902 FORD ANALYST 3000 20
7777 SUSU CLERK 3000 20
7499 ALLEN SALESMAN 1600 30
7521 WARD SALESMAN 1250 30
7654 MARTIN SALESMAN 1250 30
7698 BLAKE MANAGER 2850 30
7844 TURNER SALESMAN 1500 30
EMPNO ENAME JOB SAL DEPTNO
---------- ---------- --------- ---------- ----------
7900 JAMES CLERK 950 30
12 rows selected.
#6条记录插入成功。
--切换日志:
sys@PROD>alter system switch logfile;
System altered.
#重做日志已经切换。
--已经切换日志:
sys@PROD>select group#,archived,status from v$log;
GROUP# ARC STATUS
---------- --- ----------------
1 YES ACTIVE
2 NO CURRENT
3 YES UNUSED
#日志切换成功,第一组日志正在归档。
--再次查看日志文件:
sys@PROD>select group#,archived,status from v$log;
GROUP# ARC STATUS
---------- --- ----------------
1 YES INACTIVE
2 NO CURRENT
3 YES UNUSED
#归档完成。
--系统层删除已经归档的地第1组日志文件组:
!rm /u01/app/oracle/oradata/PROD/redo01.log
sys@PROD>!rm /u01/app/oracle/oradata/PROD/redo01.log
sys@PROD>!ls /u01/app/oracle/oradata/PROD/redo01.log
ls: /u01/app/oracle/oradata/PROD/redo01.log: No such file or directory
sys@PROD>!rm /u01/app/oracle/oradata/PROD/redo01b.log
sys@PROD>!ls /u01/app/oracle/oradata/PROD/redo01b.log
ls: /u01/app/oracle/oradata/PROD/redo01b.log: No such file or directory
--尝试打开数据库:
sys@PROD>startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 8104
Session ID: 1 Serial number: 5
--强行关闭:
sys@PROD>shutdown abort;
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdef extension doesn't exist
sys@PROD>
--重新启动数据库到mount状态:
[oracle@enmo ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 21 22:50:46 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
PROD>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
--清空第1组日志文件:
PROD>alter database clear logfile group 1;
Database altered.
--尝试打开数据库:
PROD>alter database open;
Database altered.
PROD>select group#,archived,status from v$log;
GROUP# ARC STATUS
---------- --- ----------------
1 YESUNUSED
2 YESINACTIVE
3 NO CURRENT
#数据库已经打开,并且已经清空日志组1。
--当丢失已经归档了的日志文件时候尝试打开数据库,如果不能打开并报错,
并报ORA-03113错误,此时强行关库重新启动到mount状态,清空丢失了的日志文件组,
然后再启动到open状态,这样不会丢失数据库的数据,也不许以resetlogs方式打开数据库,
就可以轻松恢复数据库。