一、理解 oracle 11g 的 UNDO 表空间的作用和工作机制

1,对于 DML 语句来说,只要修改了数据块,Oracle 数据库就会将修改前的数据保留下来,保存在 undo segment 里,而 undo segment 则保存在 undo 表空间里。

2,对于 UNDO 的管理,有手工 UNDO 管理和自动 UNDO 管理,11g 默认使用自动 UNDO 管理

3,UNDO 的作用:提供一致性读、回滚事务、实例恢复

4、UNDO 表空间:UNDO SEGMENT 则保存在 UNDO 表空间里,数据库中可以同时存在多个 undo 表空间,但是在一个时间点上,数据库只能使用一个 undo 表空间。

如果将 undo_tablespace 参数设置为另外一个 undo 表空间的名字,则叫做 undo 表空间的切换。

5、undo_retention:该参数以秒为单位,表示当事务提交或回滚以后,该事务所使用的 undo 块里的数据需要保留多长时间:当保留的时间超过 undo_retention 所指定的时间以后,该 undo 块才能够被其他事务覆盖

6、rentention garentee:从 Oracle 10g 开始,可以通过为 Undo 表空间设置 retention guarantee 属性,可以达到的效果是:当 undo 数据文件不能自动扩展,并且 undo 块不够用时,直接报错,而不是

覆盖那些 Inactive 而又没有 expired 的undo 块;

7,查看系统中的 UNDO 表空间:select * from dba_tablespaces;

8,查看 UNDO 表空间的管理方式:手工管理和自动管理:show parameter undo

二、掌握 oracle 11g 的 UNDO 表空间的相关操作

1,增加一个回滚表空间 undo tablespace ,叫做 undotbs2,用来存放回滚段中的数据,纪录数据改变的旧值,采用 local 方式管理存储

create undo tablespace undotbs2 datafile 'D:\add\Administrator\oradata\orcl\undotbs201.dbf' size 10m autoextend on;

2,给回滚表空间 undotbs2 增加一个数据文件:

alter tablespace undotbs2 add datafile 'D:\app\Administrator\oradata\orcl\undotbs202.dbf' size 10m;

select * from dba_data_files;  --查看数据文件

3,切换 undo 表空间:alter system set undo_tablespace = undotbs2;

4,启用 rentention garentee

alter tablespace undotbs1 retention guarantee;

select tablespace_name, retention from dba_tablespaces;  --查询 UNDO 表是否启用 rentention garentee

5,取消 rentertion garentee;

alter tablespace undotbs1 retention noguarantee;

6,重要视图:v$undostat 每十分钟更新一次,记录了 UNDO 表空间的使用情况

select to_char(begin_time,'yyyymmdd hh24:mi:ss') , to_char(end_time, 'yyyymmdd hh24:mi:ss') , undoblks,txncount from v$undostat;

三、理解 oracle 11g 中 UNDO 表空间的新特性:RMAN UNDO 备份优化

1,在 ORACLE DATABASE 11g 中,ORACLE 引入了一个新的特性 RMAN UNDO 备份优化。在 RMAN 备份 UNDO 表空间时,提交事务的 UNDO 信息将不备份,这个特性随 RMAN 强制启用

说明:在一个繁忙的生产环境中,UNDO 表空间可能占用几十GB的空间,全部备份显然并不合理,这一特性是许多 DBA 斯特已久的