这篇文章重点讨论Redo丢失的几种情况,及每种情况的处理方法。

一.说明:
1.以下所说的当前日志指日志状态为CURRENT,ACTIVE,非当前日志指日志状态为INACTIVE
2.不用考虑归档和非归档模式,2种模式下的Redo丢失情况一样。


二.丢失Redo的4种情况:

第一种情况:非当前日志,正常关闭。
第二种情况:非当前日志,非正常关闭。
第三种情况:当前日志,正常关闭。
第四种情况:当前日志,非正常关闭。


三.处理方法:

第一、二种情况的处理方法一样,直接把日志文件clear即可。
SQL> alter database clear logfile group 3;
SQL> alter database clear unarchived logfile group 3;//如果INACTIVE状态的在线Redo还未归档,增加关键字unarchived完成clear操作。(ACTIVE,INACTIVE都有可能未完成归档,归档是否完成可以查看v$log.archived字段)。

例子:

SQL> startup mount

ORACLE 例程已经启动。

Total System Global Area  263639040 bytes

Fixed Size                  1384012 bytes

Variable Size             167772596 bytes

Database Buffers           88080384 bytes

Redo Buffers                6402048 bytes

数据库装载完毕。

SQL> select group#,thread#,status,archived from v$log;

GROUP#    THREAD# STATUS                           ARCHIV

---------- ---------- -------------------------------- ------

1          1 CURRENT                          NO

3          1 ACTIVE                           NO

2          1 INACTIVE                         YES

SQL> alter database clear logfile group 3;

alter database clear logfile group 3

*

第 1 行出现错误:

ORA-01624: 日志 3 是紧急恢复实例 orcl (线程 1) 所必需的

ORA-00312: 联机日志 3 线程 1: 'E:\APP\ORADATA\ORCL\REDO03.LOG'

SQL> alter database clear logfile group 2;

数据库已更改。

第三种情况的处理办法:
SQL>startup mount;
SQL>recover database until cancel;
SQL>alter database open resetlogs;

例子1:

SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount
ORACLE 例程已经启动。
 
Total System Global Area  263639040 bytes
Fixed Size                  1384012 bytes
Variable Size             167772596 bytes
Database Buffers           88080384 bytes
Redo Buffers                6402048 bytes
数据库装载完毕。
SQL> alter database open resetlogs;
alter database open resetlogs
*
第 1 行出现错误:
ORA-01139: RESETLOGS 选项仅在不完全数据库恢复后有效
 
 
SQL> recover database until cancel;
完成介质恢复。
SQL> alter database open resetlogs;
数据库已更改。

例子2(第三种情况的第二个处理方法):

SQL> shutdown immediate

数据库已经关闭。

已经卸载数据库。

ORACLE 例程已经关闭。

SQL> startup mount

ORACLE 例程已经启动。

Total System Global Area  263639040 bytes

Fixed Size                  1384012 bytes

Variable Size             167772596 bytes

Database Buffers           88080384 bytes

Redo Buffers                6402048 bytes

数据库装载完毕。

SQL> select group#,thread#,status,archived from v$log;

GROUP#    THREAD# STATUS                           ARCHIV

---------- ---------- -------------------------------- ------

1          1 CURRENT                          NO

3          1 INACTIVE                         YES

2          1 INACTIVE                         YES

SQL> alter database clear logfile group 2;

数据库已更改。

SQL> alter database clear logfile group 3;

数据库已更改。

SQL> alter database clear unarchived logfile group 1;

数据库已更改。

这里CURRENT的Redo日志文件组能被clear unarchived。

SQL> alter database open;

数据库已更改。

如果Redo日志文件丢失,clear操作完成之后将在原有位置创建新的Redo日志文件。

第四种情况的处理方法:

1.通过备份来还原、恢复数据。
2.通过修改参数文件中的参数
_allow_resetlogs_corruption=TRUE
来强制启动数据库。<<<<  虽然能够启动数据库到open状态,但是启动后的数据库数据字典、数据有可能导致不一致的情况出现,故需要在open下把整个数据库export,然后删除库,重建,再将export的数据import到新的数据库中。

四.验证数据库是否正常关闭的方法

SQL> select open_mode from v$database;

OPEN_MODE

--------------------

READ WRITE

SQL> select status from v$instance;

STATUS

------------

OPEN

SQL> select file#,checkpoint_change#,fuzzy from v$datafile_header;

FILE# CHECKPOINT_CHANGE# FUZ

---------- ------------------ ---

1            1165820 YES

2            1165820 YES

3            1165820 YES

4            1165820 YES

FUZZY bit in datafile header means that there may have been writes into a datafile after the last checkpoint. E.g. there may be changes written to datafile with higher SCN than checkpoint_change# stored in datafile header (seen from v$datafile_header.checkpoint_change#).
        FUZYY表示模糊性,意思是,该数据文件处于模糊状态,在最近一次CHECKPOINT后,该文件上的数据可能被修改过了,但没来得及更新到该文件上(或者该文件不知道),需要读取日志信息来判断。

SQL> select file#,checkpoint_change#,last_change# from v$datafile;

FILE# CHECKPOINT_CHANGE# LAST_CHANGE#

---------- ------------------ ------------

1            1165820

2            1165820

3            1165820

4            1165820

由于数据库是打开的状态,所以终止SCN是空,SCN的内容可参考文章:http://space.itpub.net/23135684/viewspace-627343

SQL> shutdown immediate

数据库已经关闭。

已经卸载数据库。

ORACLE 例程已经关闭。

SQL> startup mount

ORACLE 例程已经启动。

Total System Global Area  313860096 bytes

Fixed Size                  1384352 bytes

Variable Size             155189344 bytes

Database Buffers          150994944 bytes

Redo Buffers                6291456 bytes

数据库装载完毕。

SQL> select file#,checkpoint_change#,fuzzy from v$datafile_header;

FILE# CHECKPOINT_CHANGE# FUZ

---------- ------------------ ---

1            1166324 NO

2            1166324 NO

3            1166324 NO

4            1166324 NO

在正常管理数据库的情况下,FUZZY字段都应该是NO,表示没有模糊不清的SCN存储在数据文件中。

SQL> select file#,checkpoint_change#,last_change# from v$datafile;

FILE# CHECKPOINT_CHANGE# LAST_CHANGE#

---------- ------------------ ------------

1            1166324      1166324

2            1166324      1166324

3            1166324      1166324

4            1166324      1166324

正常关闭数据库的终止SCN应该和启动SCN相同。FUZZY等于NO,且数据库的终止SCN等于启动SCN等于数据文件SCN,那么可以认为数据库是正常关闭,且在打开数据库之前不需要执行实例恢复或Crash恢复。

SQL> alter database open;

数据库已更改。

SQL> shutdown abort

ORACLE 例程已经关闭。

SQL> startup mount

ORACLE 例程已经启动。

Total System Global Area  313860096 bytes

Fixed Size                  1384352 bytes

Variable Size             155189344 bytes

Database Buffers          150994944 bytes

Redo Buffers                6291456 bytes

数据库装载完毕。

SQL> select file#,checkpoint_change#,fuzzy from v$datafile_header;

FILE# CHECKPOINT_CHANGE# FUZ

---------- ------------------ ---

1            1166327 YES

2            1166327 YES

3            1166327 YES

4            1166327 YES

非正常关闭数据库实例,FUZZY字段的值是YES。

SQL> select file#,checkpoint_change#,last_change# from v$datafile;

FILE# CHECKPOINT_CHANGE# LAST_CHANGE#

---------- ------------------ ------------

1            1166327

2            1166327

3            1166327

4            1166327

非正常关闭数据库实例,终止SCN依然为空。那么,在数据库被打开之前必须使用归档Redo日志完成实例恢复或Crash恢复。

第四种的测试案例:

[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 22 14:01:31 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from v$log;

GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
1 1 1 52428800 512 1 NO CURRENT 986240 22-OCT-18 2.8147E+14
2 1 0 52428800 512 1 YES UNUSED 0 0
3 1 0 52428800 512 1 YES UNUSED 0 0

SQL> select * from v$logfile ;

GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- ----------------------------------------- -------------------------
3 ONLINE /data/datafile/prod3/redo03.log NO
2 ONLINE /data/datafile/prod3/redo02.log NO
1 ONLINE /data/datafile/prod3/redo01.log NO

SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@prod dbs]$ rm /data/datafile/prod3/redo01.log
[oracle@prod dbs]$ rm /data/datafile/prod3/redo02.log
[oracle@prod dbs]$ rm /data/datafile/prod3/redo03.log
[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 22 14:02:17 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown abort
ORACLE instance shut down.
SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 22 14:02:29 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1185853440 bytes
Fixed Size 2252664 bytes
Variable Size 754974856 bytes
Database Buffers 419430400 bytes
Redo Buffers 9195520 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/data/datafile/prod3/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL>
SQL> create pfile from spfile ;

File created.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$
[oracle@prod dbs]$ echo "*._allow_resetlogs_corruption=TRUE">> initprod3.ora

[oracle@prod dbs]$ cat initprod3.ora
prod3.__db_cache_size=419430400
prod3.__java_pool_size=16777216
prod3.__large_pool_size=83886080
prod3.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
prod3.__pga_aggregate_target=486539264
prod3.__sga_target=704643072
prod3.__shared_io_pool_size=0
prod3.__shared_pool_size=167772160
prod3.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/prod3/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/data/datafile/prod3/control01.ctl','/data/datafile/prod3/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='prod3'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=prod3XDB)'
*.local_listener='LISTENER_PROD3'
*.memory_target=1189085184
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*._allow_resetlogs_corruption=TRUE

[oracle@prod dbs]$
[oracle@prod dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 22 14:04:20 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprod3.ora';
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprod3.ora';
ORACLE instance started.

Total System Global Area 1185853440 bytes
Fixed Size 2252664 bytes
Variable Size 754974856 bytes
Database Buffers 419430400 bytes
Redo Buffers 9195520 bytes
SQL> alter database mount ;

Database altered.

SQL> alter database open ;
alter database open
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/data/datafile/prod3/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> recover database until cancel ;
ORA-00279: change 986243 generated at 10/22/2018 13:59:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_990194382.dbf
ORA-00280: change 986243 for thread 1 is in sequence #1

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_990194382.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_990194382.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

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: '/data/datafile/prod3/system01.dbf'

SQL> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs ;

Database altered.

SQL> select file#,checkpoint_change#,fuzzy from v$datafile_header;

FILE# CHECKPOINT_CHANGE# FUZ
---------- ------------------ ---
1       986247   YES
2       986247   YES
3      986247   YES
4      986247   YES

SQL> select file#,checkpoint_change#,last_change# from v$datafile;

FILE# CHECKPOINT_CHANGE# LAST_CHANGE#
---------- ------------------ ------------
1           986247
2           986247
3          986247
4          986247

SQL

五.结论:
    非正常关闭的当前日志丢失,可能导致数据库启动后的混乱,并可能造成少量数据的丢失。其他情况不会导致数据的丢失。

Redo丢失的4种情况及处理方法的更多相关文章

  1. Oracle redo 日志损坏的几种情况下的恢复

    Oracle redo 日志损坏的几种情况下的恢复 第一:损坏的redo为非正在使用的redo log 1.归档模式,不是当前正在日志损坏,数据库打开模式. 模拟损坏:SQL> select * ...

  2. Unix网络编程(3)——C/S模型几种情况

    UNP第五章描述了在客户端和服务器连接建立之后会出现的几种情况,并给出了解决方案,做一个简单的总结. 先给出这个简单的回射C/S程序的模型如下图.   1.客户端和服务器正常终止连接 客户端从标准输入 ...

  3. Git应用—05Git文件冲突合并的几种情况(转载)

    git文件冲突合并的几种情况 https://xieye.iteye.com/blog/2433229 本文描述了git冲突的几种常见情况和解决方案,老鸟请直接忽略本文.假设冲突文件是 test/Te ...

  4. DG备库,实时应用如何判断,MR进程,及MRP应用归档,三种情况的查询及验证

    本篇文档学习,DG备库,实时应用如何判断,MR进程,及MRP应用归档,三种情况的查询及验证 1.取消MRP进程 备库查询进程状态select process,client_process,sequen ...

  5. Tomcat内存溢出的三种情况及解决办法分析

    Tomcat内存溢出的原因 在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样. 这里根据平时遇到的情况和相关资料进行一个总结.常见的一般会有下面三种 ...

  6. Objective C中数组排序几种情况的总结

    总结OC中数组排序3种方法:sortedArrayUsingSelector:;sortedArrayUsingComparator:;sortedArrayUsingDescriptors: 数组排 ...

  7. js内存泄露的几种情况

    想解决内存泄露问题,必须知道什么是内存泄露,什么情况下出现内存泄露,才能在遇到问题时,逐个排除.这里只讨论那些不经意间的内存泄露. 一.什么是内存泄露 内存泄露是指一块被分配的内存既不能使用,又不能回 ...

  8. html/css基础篇——DOM中关于脱离文档流的几种情况分析

    所谓的文档流,指的是元素排版布局过程中,元素会自动从左往右,从上往下的流式排列.并最终窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素.脱离文档流即是元素打乱了这个排列,或是从排版中拿走. ...

  9. LoadRunner 场景运行error的几种情况

    一. Error -27727: Step download timeout (120 seconds)has expired when downloading resource(s). Set th ...

随机推荐

  1. 用js实现博客打赏功能

    前几天在一个博客中看到有一个打赏功能.其实简单说来就是在页面中加入动态DOM节点,使用的也是简单的HTML.CSS.JS这些前端的一些简单知识.在GitHub上有开源的代码,这里稍加改造就可以用在自己 ...

  2. 为什么用bower 安装bootstrap而不用npm来安装?

    NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜索.发布等. npm的背后,是基于couchdb ...

  3. CSS实现两列布局,一列固定宽度,一列宽度自适应方法

    不管是左是右,反正就是一边宽度固定,一边宽度自适应. 博客园的很多主题也是这样设计的,我的博客也是右侧固定宽度,左侧自适应屏幕的布局方式. html代码: <div id="wrap& ...

  4. Java Filter防止sql注入攻击

    原理,过滤所有请求中含有非法的字符,例如:, & < select delete 等关键字,黑客可以利用这些字符进行注入攻击,原理是后台实现使用拼接字符串,案例:某个网站的登入验证的SQ ...

  5. web框架的本质

    一 web框架的本质及自定义web框架 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端,基于请求做出响应,客户都先请求,服务端做出对应的响 ...

  6. Android为TV端助力 很详细的序列化过程Parcelable

    直接上代码:注释都写的很清楚了. public class Entry implements Parcelable{ public int userID; public String username ...

  7. 小米手机Toast显示带应用名称问题解决方法

    近期为了适配刘海屏,向公司申购了一步小米8的手机,然后测试人员那边测出来一堆适配的问题,其中有一个每一个Toast会显示app的名称+显示的内容,然后网上查找了一下解决方法记录一下,顺便封装了Toas ...

  8. (网页)HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath(转)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. (后端)SpringBoot中Mybatis打印sql(转)

    原文地址:https://www.cnblogs.com/expiator/p/8664977.html 如果使用的是application.properties文件,加入如下配置: logging. ...

  10. (后端)解决code唯一码(java)简便方法

    public String next() { long appBootTimes = systemVariableService.getAppBootTimes(); return Long.toSt ...