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的区别详解的更多相关文章
- 基于python中staticmethod和classmethod的区别(详解)
例子 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 class A(object): def foo(self,x): print "executing foo ...
- DOS批处理中%cd%与%~dp0的区别详解
转载:https://www.jb51.net/article/105325.htm DOS批处理中%cd%与%~dp0的区别详解 Windows下批处理中%cd%和%~dp0都能用来表示当前 ...
- Oracle 中UNDO与REDO的差别具体解释
一 为了更清楚的看出2者差别,请看下表: UNDO ...
- oracle中的exists 和 in 用法详解
以前一直不知道exists和in的用法与效率,这次的项目中需要用到,所以自己研究了一下.下面是我举两个例子说明两者之间的效率问题. 前言概述: “exists”和“in”的效率问题,涉及到效率问题也就 ...
- C#中struct和class的区别详解
本文详细分析了C#中struct和class的区别,对于C#初学者来说是有必要加以了解并掌握的. 简单来说,struct是值类型,创建一个struct类型的实例被分配在栈上.class是引用类型,创建 ...
- Java中的==和equals的区别详解
1.基础知识 (1)String x = "hello"; (2)String x = new String ("hello"); 第1种方式的工作机制是,首先 ...
- C#中struct和class的区别详解 (转载)
本文详细分析了C#中struct和class的区别,对于C#初学者来说是有必要加以了解并掌握的. 简单来说,struct是值类型,创建一个struct类型的实例被分配在栈上.class是引用类型,创建 ...
- 深入Oracle的left join中on和where的区别详解
-- from http://blog.itpub.net/30175262/viewspace-1472060/ 今天遇到一个求某月所有天数的统计结果,如果某日的结果是0也需要显示出来,即: 日期 ...
- C#中struct与class的区别详解
转自:http://blog.csdn.net/justlovepro/archive/2007/11/02/1863734.aspx 有这么几点不同: 1.struct 是值类型,class是对象类 ...
- Lua中ipairs和pairs的区别详解
迭代器for遍历table时,ipairs和pairs的区别: 区别一:ipairs遇到nil会停止,pairs会输出nil值然后继续下去 区别二: , b = , x = , y = , " ...
随机推荐
- Django-Import-Export插件关于外键的处理
前言 Django-Import-Export是一款很好用很方便的Django数据导出导入插件,可以和DjangoAdmin管理后台完美集成,只需要少量的代码配置即可方便实现你要的多种格式导出导入,关 ...
- [转帖]TLS1.3 正式版发布 — 特性与开启方式科普
https://cloud.tencent.com/developer/article/1376033 互联网工程指导委员会(IETF)释出了传输层安全性协议的最新版本 TLS 1.3.TLS 被广泛 ...
- [转帖]《Linux性能优化实战》笔记(23)—— 内核线程 CPU 利用率过高,perf 与 火焰图
在排查网络问题时,我们还经常碰到的一个问题,就是内核线程的 CPU 使用率很高.比如,在高并发的场景中,内核线程 ksoftirqd 的 CPU 使用率通常就会比较高.回顾一下前面学过的 CPU 和网 ...
- 多个物理磁盘挂载到同一目录的方法 (lvm 软raid)
多个物理磁盘挂载到同一目录的方法 (lvm 软raid) 背景 公司里面的一台申威3231的机器 因为这个机器的raid卡没有操作界面. 所以只能够通过命令行方式创建raid 自己这一块比较菜, 想着 ...
- Nacos集群启动注意事项
简介 Nacos是阿里巴巴开源的一套服务注册发现的应用 使用简单灵活, 是spring Cloud Alibaba的组成部分 现在拆分微服务的部署情况下,极大的需求nacos服务作为支撑 单点情况下存 ...
- 公司内部自建DNS的办法 使用私有域名的方法
最近总是有一个需求,需要自己弄一些服务器域名之类的. 修改hosts总是比较麻烦,所以想了一个简单办法, 自己搭建一个dns服务器, 本来想用最简单的 dnsmasq 但是发现总是不成功, 然后找了另 ...
- 飞腾2000+银河麒麟v10安装redis的注意事项
先说一下结论 无法复用ubuntu上面编译的二进制文件 无法直接使用docker官网下面的arm64的镜像运行 无法直接使用redis6.0.10最新版本编译运行 可以使用redis5.0.4 进行编 ...
- fiddler如何抓取https请求
pc端browse 1.打开下载好的fiddler,点击tools选择options后进入https tab下,勾选Decrypt HTTPS CONNECTS 和Ignore server cer ...
- 微服务用yml安装系统(第一版)
当用微服务安装系统后,面临服务较多,一个一个安装比较麻烦,是否有统一的脚本可以直接执行安装呢?答案是肯定的: 1.首先介绍一下所有安装脚本,如下图 spd-volume:是各服务外挂的资料卷 comm ...
- hadoop实践01---hdfs分布式集群搭建与启动
一.hdfs集群组成结构