删除online日志测试及ORA(4)

Total System Global Area  524288000 bytes
Fixed Size    1220384 bytes
Variable Size  322961632 bytes
Database Buffers  197132288 bytes
Redo Buffers    2973696 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/ora10g/redo03.log'

由于启动数据库会检查所有的文件,读取到在线日志文件redo03.log时,就报错了,因为已经被删除

--还原数据库
SYS@ora10g> recover database until cancel;
Media recovery complete.
SYS@ora10g> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

由于之前是正常关闭数据库,在线日志的内容已经写到归档日志文件,利用归档日志进行还原,而还原后的数据库,必须用resetlogs方式来OPEN数据库

SYS@ora10g> alter database open resetlogs;

Database altered.

SYS@ora10g> conn zlm/zlm
Connected.
ZLM@ora10g> select count(*) from t1;

COUNT(*)
----------
20

ZLM@ora10g>
 
只要是正常关闭数据库的,并且开启了归档,那么即便是删除了current的在线日志,也是可以将数据库重新打开的,并且不会丢失数据(由归档来保证)

测试3:非正常关闭数据库,并删除当前在线日志文件

--添加测试数据后,abort方式关闭数据库
ZLM@ora10g> select group#,thread#,status,archived from v$log;

GROUP#    THREAD# STATUS      ARC
---------- ---------- ---------------- ---
 1    1 CURRENT      NO
 2    1 UNUSED      YES
 3    1 INACTIVE      YES

ZLM@ora10g> insert into t1 select * from dba_objects where rownum<11;

10 rows created.

ZLM@ora10g> select count(*) from t1;

COUNT(*)
----------
30

ZLM@ora10g> alter system archive log current;

System altered.

ZLM@ora10g> select group#,thread#,status,archived from v$log;

GROUP#    THREAD# STATUS      ARC
---------- ---------- ---------------- ---
 1    1 ACTIVE      YES
 2    1 CURRENT      NO
 3    1 INACTIVE      YES

ZLM@ora10g> shutdown abort
ORA-01031: insufficient privileges
ZLM@ora10g> conn / as sysdba
Connected.
SYS@ora10g> shutdown abort
ORACLE instance shut down.
SYS@ora10g>

--OS上将current在线日志文件redo02.log删除
[oracle@ora10g ora10g]$ rm -f redo02.log
[oracle@ora10g ora10g]$ ls -l redo*
-rw-r----- 1 oracle oinstall 52429312 Jun 24 11:16 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Jun 24 11:08 redo03.log

--再次启动数据库
SYS@ora10g> startup
ORACLE instance started.

Total System Global Area  524288000 bytes
Fixed Size    1220384 bytes
Variable Size  327155936 bytes
Database Buffers  192937984 bytes
Redo Buffers    2973696 bytes
Database mounted.
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/ora10g/redo02.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

SYS@ora10g> alter database clear logfile group 2;
alter database clear logfile group 2
*
ERROR at line 1:
ORA-01624: log 2 needed for crash recovery of instance ora10g (thread 1)
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/ora10g/redo02.log'

SYS@ora10g> recover database until cancel;
ORA-00279: change 1497127 generated at 06/24/2015 11:08:48 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2015_06_24/o1_mf_1_2_%u_.arc
ORA-00280: change 1497127 for thread 1 is in sequence #2

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora10g/system01.dbf'

ORA-01112: media recovery not started

SYS@ora10g>

之前使用的方法,在此处都不成立,原因是数据库强制要求current的在线日志文件需要crash recover,重新创建自然是不行的,由于是非正常关闭数据库,也没有写入归档文件,当然也无法进行还原,那么此时只有通过别的方法来将数据库OPEN了,当然丢失数据已经是不可避免的了,也就是刚才current在线日志文件中未归档的那部分,即t1表中最后插入的10条记录,权衡利弊,即便是丢数据,也要先将数据库拉起来,那么可以通过设置隐含参数"_allow_resetlogs_corruption=true"来实现

SYS@ora10g> create pfile from spfile;

File created.

SYS@ora10g> show parameter spfile

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6d9cdedd800e70452f82f714bd7e9586.html