Oracle 中UNDO与REDO的差别具体解释
一 为了更清楚的看出2者差别,请看下表:
UNDO REDO
Record of | How to undo a change | How to reproduce a change |
Used for | Rollback, Read-Consistency | Rolling forward DB Changes |
Stored in | Undo segments | Redo log files |
Protect Against | Inconsistent reads in multiuser systems | Data loss |
二 以下我们来通过实例说明undo 和 redo的关系:
1 我们将证明下面事实:
- oracle 中redo包括undo;
- checkpoint 会导致脏数据写入datafile;
- buffers 会被写入当前的undo 表空间
2 操作步骤:
3 详细实现:
SQL> show parameter undo_tablespace NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
- 创建Undo表空间 undotbs2:
SQL> create undo tablespace undotbs2 datafile '/u01/app/oracle/undotbs2.dbf'
2 size 100m; Tablespace created.
- 创建表空间 test_undo
SQL> create tablespace test_undo datafile '/u01/app/oracle/test_undo.dbf'
2 size 128k; Tablespace created.
SQL> create table test_undo_tab(txt char(1000)) tablespace test_undo; Table created. SQL> insert into test_undo_tab values ('teststring1'); 1 row created. SQL> insert into test_undo_tab values ('teststring2'); 1 row created. SQL> commit;
- 运行手工检查点。将以上改变写入数据文件:
SQL> alter system checkpoint; System altered.
- 设置undotbs2为当前undo表空间:
SQL> alter system set undo_tablespace=undotbs2; System altered. SQL> show parameter undo_tablespace; NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS2
- 进行日志切换使当前日志不包括字符串teststring
SQL> alter system switch logfile; System altered.
SQL> col member for a30
SQL> select member, l.status from v$log l, v$logfile f
2 where l.group# = f.group#
3 and l.status = 'CURRENT'; MEMBER STATUS
------------------------------ ----------------
/u01/app/oracle/oradata/orcl/r CURRENT
edo02.log
SQL> update test_undo_tab set txt = 'teststring_uncommitted'
2 where txt = 'teststring1'; 1 row updated.
SQL> update test_undo_tab set txt = 'teststring_committed'
where txt = 'teststring2';
commit;
[oracle@dylan ~]$ strings /u01/app/oracle/oradata/orcl/redo02.log | grep teststring
teststring_uncommitted
teststring1 teststring_committed teststring2
[oracle@dylan ~]$ strings /u01/app/oracle/test_undo.dbf | grep teststring
teststring2
teststring1
SQL> alter system checkpoint;
[oracle@dylan ~$ strings /u01/app/oracle/test_undo.dbf|grep teststring teststring_committed ,
teststring_uncommitted
[oracle@dylan ~]$ strings /u01/app/oracle/undotbs2.dbf | grep teststring teststring2
teststring1
SQL>drop tablespace test_undo including contents and datafiles;
alter system set undo_tablespace=undotbs1;
drop tablespace undotbs2 including contents and datafiles;
三 进一步探讨:
Let’s see what will happen if undo is stored in redo logs only.
假设仅将undo信息存储于redo logs会怎么样?
A redo log can be reused once changes protected by it have been written to datafiles (and archivelogs if database is in archivelog mode).
It implies that if I make a change and do not commit it
- Change is written to a redo log 假设我改变的数据而没提交。此时改变将记录到redo log
- checkpoint takes place 检查点发生
- uncommitted change is written to datafile 后未提交的数据写入了数据文件
- I decide to rollback the change 这时我打算回滚
- If redo log has not been overwritten 假设redo log没被覆盖
. search entire redo log for the undo and then rollback 那么搜素整个redo log进行回滚操作
else (redo log has been overwritten)
. undo information is not available for rollback. 否则将无法回滚,undo信息已丢失!
One might argue that if somehow a redo log is not allowed to be overwritten until it contains active undo, we might be able to manage with undo stored in redo logs only. This solution is not feasible as
- size of redo logs will grow enormously large very soon as thet contain both undo and redo (a user might decide not to end a transaction for months)
- to rollback a change, enormous amount of data in redo logs (both redo and undo) will have to be searched leading to degraded performance
- there will be contention on redo logs as they are being used for both
. writing redo and undo
. reading to rollback a change
有人或许会争论:那就不同意redo log 覆盖undo 信息直到包括新的undo,这样redo log将变得异常大从而影响系统性能!
Hence, undo information has to be stored separately from redo and is used for rolling back uncommited transactions . The undo stored in undo buffers/undo tablespace is additionally used for
- read consistency 读一致性
- flashback query 闪回查询
- flashback version query 闪回版本号查询
---------------------------------------
Oracle 中UNDO与REDO的差别具体解释的更多相关文章
- Oracle中undo表空间的切换
查看操作系统: SQL> !cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 7.4 (Maipo)查看数据库版本: ...
- Oracle中NVARCHAR2与VARCHAR2的差别
NVARCHAR2在计算长度时和字符集相关的: 比如数据库是中文字符集时以长度10为例, 1.NVARCHAR2(10)是能够存进去10个汉字的.假设用来存英文也仅仅能存10个字符. 2.而VARCH ...
- Oracle性能优化之oracle中常见的执行计划及其简单解释
一.访问表执行计划 1.table access full:全表扫描.它会访问表中的每一条记录(读取高水位线以内的每一个数据块). 2.table access by user rowid:输入源ro ...
- Java中Vector与ArrayList的差别具体解释
首先看这两类都实现List接口,而List接口一共同拥有三个实现类.各自是ArrayList.Vector和LinkedList.List用于存放多个元素,可以维护元素的次序,而且同意元素的反复. 3 ...
- 【知识点整理】Oracle中NOLOGGING、APPEND、ARCHIVE和PARALLEL下,REDO、UNDO和执行速度的比较
[知识点整理]Oracle中NOLOGGING.APPEND.ARCHIVE和PARALLEL下,REDO.UNDO和执行速度的比较 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 ...
- Oracle Undo 和 Redo
1. REDO(重做信息) Redo log file(重做日志文件),是数据库的事务日志. Oracle维护着两类重做日志文件:在线(online)重做日志文件和归档(archived)重做日志文件 ...
- 转:C#中Undo/Redo的一个简易实现
一个比较常见的改进用户体验的方案是用Redo/Undo来取代确认对话框,由于这个功能比较常用,本文简单的给了一个在C#中通过Command模式实现Redo/Undo方案的例子,以供后续查询. clas ...
- Visio中的Undo和Redo
1.Visio默认Undo和Redo操作是可用的,Appliacation中的UndoEnabled标志Undo和Redo操作是否可用. m_Visio.Window.Application.Undo ...
- 记一次ORACLE的UNDO表空间爆满分析过程
这篇文章是记录一次ORACLE数据库UNDO表空间爆满的分析过程,主要整理.梳理了同事分析的思路.具体过程如下所示: 早上收到一数据库服务器的UNDO表空间的告警邮件,最早一封是7:55发出的(监控作 ...
随机推荐
- 最详细的CentOS 6与7对比(一):常见设置对比
本主题将从3个角度进行对比 常见设置(CentOS 6 vs CentOS 7) 服务管理(Sysvinit vs Upstart vs Systemd) 性能测试(cpu/mem/io/oltp) ...
- linux 标准输出和后台运行
一.后台运行程序 至需要在命令后面加上一个 & 即可 # command & 例如: python test.py & 二.标准输出.标准错误输出 # command > ...
- [XJOI]noip44 T3还有这种操作
还有这种操作 ttt 最近在学习二进制, 他想知道小于等于N的数中有多少个数的二进制表示中有偶数个1. 但是他想了想觉得不够dark,于是他增加了若干次操作,每次操作会将一个区间内的0变1 , 1变0 ...
- guice整合struts2与jpa,guice的使用(九)
传统我们开发一般使用ssh,但是有些微服务应用的项目我们不需要这么臃肿的框架做开发,于是采用了guice+struts2+guice作为框架组合进行了开发. 先看我们项目引用的jar包: 使用的时候一 ...
- Java 系列之spring学习--注解(三)
一.注解 使用注解之前要开启自动扫描功能 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...
- 使用DbVisualizer变量
变量可用于构建参数化SQL语句,并让DbVisualizer在执行SQL时提示您输入值.如果您重复执行相同的SQL,只是希望在同一个SQL语句中传递新数据,这很方便. 变量语法 变量格式支持设置默认值 ...
- V4L2框架之视频监控
[参考]韦东山 教学视频 一. V4L2框架: video for linux version 2 虚拟视频驱动vivi.c分析:1.分配video_device2.设置3.注册:video_regi ...
- SVN客户端安装 Linux
1.下载 [maintain@HM16-213 software]$ wget http://subversion.tigris.org/downloads/subversion-deps-1.6.1 ...
- socket 的通信过程
1.建立套接字 Linux在利用socket()系统调用建立新的套接字时,需要传递套接字的地址族标识符.套接字类型以及协议,其函数定义于net/socket.c中: asmlinkage long s ...
- 应用二:Vue之ElementUI Form表单校验
(注:本文适用于有一定Vue基础或开发经验的读者,文章就知识点的讲解不一定全面,但却是开发过程中很实用的) 表单校验是前端开发过程中最常用到的功能之一,根据个人的工作经验总结在此对表单校验功能的基 ...