在数据库服务器异常断电重启后,数据库会进行实例恢复,那么实例恢复的过程中Oracle做了什么操作呢?参考官网在这里做一下解释,菜鸟水平有限,欢迎勘正。

首先说下实例恢复的定义:

Instance recovery is the process of applying records in the online redo log to data files to reconstruct changes made after the most recent checkpoint. Instance recovery occurs automatically when an administrator attempts to open a database that was previously shut down inconsistently.

Oracle Database performs instance recovery automatically in the following situations:

  • The database opens for the first time after the failure of a single-instance database or all instances of an Oracle RAC database. This form of instance recovery is also called crash recovery. Oracle Database recovers the online redo threads of the terminated instances together.

  • Some but not all instances of an Oracle RAC database fail. Instance recovery is performed automatically by a surviving instance in the configuration.

The SMON background process performs instance recovery, applying online redo automatically. No user intervention is required.

因此我们知道非一致性关闭会引发实例恢复(一致性关闭不会,参考shutdown immediate的官方定义)同时RAC节点宕机也会在一个存活节点进行实例恢复,其过程就是重构内存中的脏块并提交,同时对未提交的做出回滚,这个过程由smon后台进程负责。

实例恢复分两阶段:
1.前滚:Rolling Forward 
Oracle根据redo日志中的记载,重现checkpoint之后的脏块队列:
    1)对于提交的事务,根据日志进行内存中的脏块重现,然后进行commit,并按正常机制正常写入磁盘。
    2)对于未提交的事务,也根据redo进行脏块重现(为何会有未提交的事务日志被写入磁盘呢?因为日志的写入是按时间排序的,一些已提交事务的写日志操作会引发之前的一些未提交事务日志的写入),对以此类脏块只是重现,oracle在此阶段完全不对此类脏块做其他操作。
由于一些未提交大事务的更改已经被写入磁盘(但依然会保持严格的日志先写机制),以及前滚过程中生成的未提交事务的脏块,oracle必须进行第二步的回滚。
2.回滚:Rolling Back
   对于所有未提交的脏块,oracle根据undo的前镜像进行回滚(行级别的逻辑反操作),重新将内存中缓存的相关数据脏块换为非脏块,并写入磁盘上的data block。

这里上一幅官网的图:

图:Basic Instance Recovery Steps: Rolling Forward and Rolling Back

图解:
我们看到实例恢复前redo日志中记载的日志对应着四种更改块(redo只记载更改):
1)已提交且被写入磁盘的更改块,oracle对这种块无需做任何操作。
2)已提交但未被写入磁盘的更改块,oracle会在前滚过程中在内存重现脏块,然后按正常机制提交。
3)未提交且未被写入磁盘的更改块。
4)未提交但已被写入磁盘的更改块。
由于回滚是按事务为单位进行处理的,因此对于3、4两种块的处理全部是在回滚阶段,oracle根据undo进行所有未提交事务的回滚操作,用前镜像覆盖掉磁盘or内存中的数据,这样就会处理掉第3、4种块。
此外,从上不难看出oracle默认undo中记载的事务进度是和redo日志中的完全一致的,不存在undo记载了事务被提交但是redo日志记录未提交的情况。
但是并不是所有情况都符合Oracle默认的预期,有时候数据库频繁掉电就可能出现无法成功进行实例恢复的情况,此时只能采取一些特殊手段对数据文件头和SCN做一些改动。
一般除非特别紧急的状况,否则不要用BBED、强制推进SCN等”偏方“去打开数据库,对于一个成功的DBA来说,做好备份和灾备永远是最重要的工作。

Instance Recovery Phases
The first phase of instance recovery is called cache recovery or rolling forward, and involves reapplying all of the changes recorded in the online redo log to the data files. Because rollback data is recorded in the online redo log, rolling forward also regenerates the corresponding undo segments.

Rolling forward proceeds through as many online redo log files as necessary to bring the database forward in time. After rolling forward, the data blocks contain all committed changes recorded in the online redo log files. These files could also contain uncommitted changes that were either saved to the data files before the failure, or were recorded in the online redo log and introduced during cache recovery.

After the roll forward, any changes that were not committed must be undone. Oracle Database uses the checkpoint position, which guarantees that every committed change with an SCN lower than the checkpoint SCN is saved on disk. Oracle Database applies undo blocks to roll back uncommitted changes in data blocks that were written before the failure or introduced during cache recovery. This phase is called rolling back or transaction recovery.

Oracle的实例恢复解析的更多相关文章

  1. SQL Server的实例恢复解析

    同Oracle一样,SQL Server在非一致性关闭的时候也会进行实例恢复(Instance Recovery),本文根据stack overflow的文章介绍一些SQL Server实例恢复的知识 ...

  2. ORACLE实例恢复过程详细分析--使用dump、BBED等多种工具结合分析

    ---友情提示,内容较多,可以从博文左上的+目录选择小节方便阅读.  实验思路:  --实验相关TRACE文件:http://download.csdn.net/detail/q947817003/6 ...

  3. Oracle 实例恢复

    -======================= -- Oracle 实例恢复 --======================= 一.Oracle实例失败 Oracle实例失败多为实例非一致性关闭所 ...

  4. Oracle Undo与脏读解析

    Undo就是用来记录保存事务操作过程中的数据,如果事务发生错误,可以之前的数据进行填补. Undo segment 是保存在表空间上的.Undo 大小是固定的,既然是固定的也就是有限的.如果保存的记录 ...

  5. dump 验证实例恢复的起点和终点

    什么时候会产生实例恢复呢?当你数据库服务器异常断电,重启数据库就会发生实例恢复.实例恢复是由数据库自动完成的,无须DBA的干涉.当然这里有个前提条件:数据文件. 在线日志文件.控制文件不得有损坏. 我 ...

  6. 大数据应用日志采集之Scribe演示实例完全解析

    大数据应用日志采集之Scribe演示实例完全解析 引子: Scribe是Facebook开源的日志收集系统,在Facebook内部已经得到大量的应用.它能够从各种日志源上收集日志,存储到一个中央存储系 ...

  7. oracle利用redo恢复

    oracle媒介恢复(Media Recovery) 官方资料 https://docs.oracle.com/database/121/ADMQS/GUID-CBC5870F-2C9A-4F67-B ...

  8. Oracle 表空间恢复

    为啥要写这个呢,因为之前遇到个场景.操作系统为Solaris的,oracle11.2.0.4. 一个运维把一张关键表drop了.然后发现recyclebin是off的,然后..然后好像只能从备份里面找 ...

  9. Oracle 数据库实例简介

      回到顶部 一:Oracle 数据库实例简介 1:数据库实例的启动顺序: 使用数据库其实就是访问内存.即:数据库实例.数据库的启动是顺序是 先 nomount ---->  mount --- ...

随机推荐

  1. centos7非centos标准服务 /etc/init.d/service_name start || stop 启动异常

    公司自己写的java程序,在centos7系统执行/etc/init.d/service_name start||stop的时候报错: grafana二次开发的程序 [root@docp1 init. ...

  2. Mysql加锁过程详解(7)-初步理解MySQL的gap锁

    Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...

  3. Python中的数据结构

    Python中的数据结构 这里总结一下Python中的内置数据结构(Built-in Data Structure):列表list.元组tuple.字典dict.集合set,涵盖的仅有部分重点,详细地 ...

  4. 错误提示:The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project The type java.lang.Object cannot b

    原文:http://www.cnblogs.com/mmzs/p/7662863.html 错误类型: 搞了很久才找到原因.解决办法写出来分享: 出现以上错误的原因是玩耍maven时多装了个jre.本 ...

  5. NGUI 做局部2d卷轴

    网上找到的都是做整个背景的卷轴动画,通常是改变纹理位置或者背景图片的x坐标 没有提到在UI界面里某个部分做卷轴动画,找了很久,才发现NGUI的Panel里的Clipping属性可以裁剪Panel的大小 ...

  6. element框架中表格的筛选功能使用说明(转载)

    一.element框架中表格的筛选功能使用说明 转载:https://blog.csdn.net/liangxhblog/article/details/80513030 在element ui 框架 ...

  7. windows10系统盘瘦身

  8. SpringBoot 之集成邮件服务.

    一.前言 Spring Email 抽象的核心是 MailSender 接口,MailSender 的实现能够把 Email 发送给邮件服务器,由邮件服务器实现邮件发送的功能. Spring 自带了一 ...

  9. JavaScript是如何工作的:与WebAssembly比较及其使用场景

    摘要: WebAssembly未来可期. 原文:JavaScript是如何工作的:与WebAssembly比较及其使用场景 作者:前端小智 Fundebug经授权转载,版权归原作者所有. 这是专门探索 ...

  10. angular select 默认值

    <select ng-model="selected" ng-options="x.id as x.name for x in users">< ...