Oracle 12c 新特性之临时Undo--temp_undo_enabled

每个

Oracle

数据库包含一组与系统相关的表空间,例如

SYSTEM

SYSAUX

UNDO&TEMP

,并且它们在

Oracle

数据库中每个都用于不同的目的。

Oracle 12c

之前,临时表生成的

Undo

记录是存储在

Undo

表空间

Redo

日志文件中

的,通用表和持久表的

undo

记录也是

存储在

Undo

表空间中的,从

Oracle 12c

开始

,临时

Undo

记录可以存储在

临时表空间中,且不再记录到

Redo

日志文件中,

这样做的主要好处在于:

减少

Undo

表空间

的使用

减少了

Redo

数据的生成

。可以在会话级别或者数据库级别来启用临时

Undo

选项。

Temporary undo records are stored in the database's temporary tablespaces and thus are not logged in the redo log. When temporary undo is enabled, some of the segments used by the temporary tablespaces store the temporary undo, and these segments are called

temporary undo segments

.You can enable or disable temporary undo for a session or for the system. To do so, set the TEMP_UNDO_ENABLED initialization parameter.

系统会广泛使用临时表作为暂存区来存放中间结果。这是因为更改这些表的速度远远超过更改非临时表的速度。性能之所以会改进,主要是因为不会为临时表中的更改直接生成重做条目。但是,对临时表(和索引)的操作的还原数据仍会记录在重做日志中。

临时表的还原数据对于在临时对象生存期中实现读取一致性和事务处理回退非常有用。除此之外,不需要该还原数据。因此,它无需保存在重做流中。例如,事务处理恢复将放弃临时对象的还原数据。

Oracle Database 12c

开始,可以将由临时表的事务处理生成的还原数据直接存储在临时表空间的一个单独还原流中,以避免将该还原数据记录在重做流中。这种新模式称为临时还原。

注:临时还原段是会话专用的。它将存储对属于相应会话的临时表(一般为临时对象)所做的更改的还原数据。

临时

Undo

:优点和设置

临时

Undo

可减少

Undo

表空间中存储的

Undo

数据量。

临时

Undo

可减小重做日志的大小。

临时

Undo

支持在具有

Oracle Active Data Guard

选件的物理备用数据库中对临时表执行

DML

操作。

SQL> ALTER SESSION SET TEMP_UNDO_ENABLED = TRUE;

SQL> ALTER SYSTEM SET TEMP_UNDO_ENABLED = TRUE;

会话首次使用临时对象时会选择临时还原模式。

启用临时还原具有以下优点:

临时还原可减少还原表空间中存储的还原数据量。还原表空间中的还原数据越少,还原记录所需要的还原保留期越实际。

临时还原可减小重做日志的大小。由于写入重做日志的数据较少,因此性能会有所提高,并且由于要进行语法分析的重做数据较少,因此,用于对重做日志记录进行语法分析的组件(如

LogMiner

)性能也会有所提高。

临时还原支持在具有

Oracle Active Data Guard

选件的物理备用数据库中对临时表执行数据操纵语言

(DML)

操作。但是,必须在主数据库上发出创建临时表的数据操纵语言

(DDL)

操作。

可以为特定会话或整个系统启用临时还原。为某个会话启用临时还原时,该会话将创建临时还原,而不影响其他会话。当会话首次使用临时对象时,系统将为该会话的其余部分设置

TEMP_UNDO_ENABLED

初始化参数的当前值。因此,如果为某个会话启用了临时还原,并且该会话使用临时对象,则无法为该会话禁用临时还原。同样,如果为某个会话禁用了临时还原,并且该会话使用临时对象,则无法为该会话启用临时还原。为系统启用临时还原时,所有现有会话和新会话都将创建临时还原。

(一)

启用临时

undo

功能

要使用这一新功能,需要做以下设置:

ü

兼容性参数必须设置为

12.0.0

或更高

ü

启用

TEMP_UNDO_ENABLED

初始化参数

ü

由于临时

undo

记录现在是存储在一个临时表空间中的,你需要有足够的空间来创建这一临时表空间

ü

对于会话级,你可以使用:

ALTER SYSTEM SET TEMP_UNDO_ENABLE=TRUE;

(二)

查询临时

undo

信息

以下所列的字典视图是用来查看或查询临时

undo

数据相关统计信息的:

ü

V$TEMPUNDOSTAT

ü

DBA_HIST_UNDOSTAT

ü

V$UNDOSTAT

要禁用此功能,你只需做以下设置:

SQL> ALTER SYSTEM|SESSION SET TEMP_UNDO_ENABLED=FALSE;

SELECT to_char(BEGIN_TIME,'dd/mm/yy hh24:mi'),

TXNCOUNT,MAXCONCURRENCY,UNDOBLKCNT,USCOUNT,

NOSPACEERRCNT

FROM V$TEMPUNDOSTAT;

V$TEMPUNDOSTAT

显示了与此数据库实例的临时还原日志相关的各种统计信息。它将显示统计数据直方图,以展示系统的运行情况。该视图的每一行会保存从实例中收集的

10

分钟间隔统计信息。各个行按

BEGIN_TIME

列值降序排列。此视图总共包含

576

行,跨越一个四天周期。此视图与

V$UNDOSTAT

视图类似。该示例显示了

V$TEMPUNDOSTAT

视图中的一些重要列:

•BEGIN_TIME

:确定时间间隔的开始。

•TXNCOUNT

:在相应的时间间隔内绑定到临时还原段的事务处理总数。

•MAXCONCURRENCY

:并行执行的最多事务处理数,这些事务处理会在相应的时间间隔内修改临时对象。

•UNDOBLKCNT

:在相应的时间间隔内占用的临时还原块总数。

•USCOUNT

:在相应的时间间隔内创建的临时还原段。

•NOSPACEERRCNT

:在相应的时间间隔内引发错误

“no space left for temporary

undo

(没有用于临时还原的剩余空间)

的总次数。

--------测试脚本

ALTER SYSTEM SET TEMP_UNDO_ENABLED=TRUE;

事务临时表:

CREATE GLOBAL TEMPORARY TABLE CGTT_DELETE_LHR AS SELECT * FROM SCOTT.EMP WHERE 1=2;

INSERT INTO CGTT_DELETE_LHR SELECT * FROM SCOTT.EMP WHERE ROWNUM<=5;

会话临时表:

CREATE GLOBAL TEMPORARY TABLE CGTT_PRESERVE_LHR ON COMMIT PRESERVE ROWS AS SELECT * FROM SCOTT.EMP WHERE 1=2;

INSERT INTO CGTT_PRESERVE_LHR SELECT * FROM SCOTT.EMP WHERE ROWNUM<=5;

SELECT * FROM CGTT_PRESERVE_LHR;

查看一张表是否临时表,可以从DBA_TABLES视图的DURATION列来查询:

SELECT UT.TABLE_NAME,

UT.TABLESPACE_NAME,

DECODE(UT.DURATION,'SYS$SESSION','会话级','SYS$TRANSACTION','事务级') T_TYPE

FROM DBA_TABLES UT

WHERE UT.TEMPORARY = 'Y'

AND UT.TABLE_NAME LIKE '%CGTT%';

SELECT to_char(BEGIN_TIME, 'yyyy-mm-dd hh24:mi') BEGIN_TIME,

TXNCOUNT,

MAXCONCURRENCY,

UNDOBLKCNT,

USCOUNT,

NOSPACEERRCNT

FROM V$TEMPUNDOSTAT;

Oracle 12c R1 之前,临时表生成的undo记录是存储在undo表空间里的,通用表和持久表的undo记录也是类似的。而在 12c R12 的临时 undo 功能中,临时 undo 记录可以存储在一个临时表空间中,而无需再存储在 undo 表空间内。临时表的UNDO信息通常用于读一致性和事务回滚,在事务完成之后,无需进行恢复,所以也就不必永久保存。这个特性完全无损Oracle的事务一致性。这样做的主要好处在于:减少 undo 表空间,由于信息不会被记录在 redo 日志中,所以减少了 redo 数据的生成。你可以在会话级别或者数据库级别来启用临时 undo 选项。

启用 temp undo 好处:

1.减少 undo 表空间

2.减少 redo 数据

3.允许在ADG中对临时表进行DML操作

启用 temp undo 要求:

1.兼容性参数必须设置为 12.0.0 或更高

2.启用 c##andy.temp_undo_ENABLED 初始化参数

3.足够的空间来创建临时表空间

开启或者禁用 temp undo:

SQL> ALTER SYSTEM|SESSION SET TEMP_UNDO_ENABLED=TRUE;

SQL> ALTER SYSTEM|SESSION SET TEMP_UNDO_ENABLED=FALSE;

16.7

Managing Temporary Undo

By default, undo records for temporary tables are stored in the undo tablespace and are logged in the redo, which is the same way undo is managed for persistent tables. However, you can use the

TEMP_UNDO_ENABLED

initialization parameter to separate undo for temporary tables from undo for persistent tables. When this parameter is set to

TRUE

, the undo for temporary tables is called

temporary undo

.

About Managing Temporary Undo

Temporary undo records are stored in the database's temporary tablespaces and thus are not logged in the redo log. When temporary undo is enabled, some of the segments used by the temporary tablespaces store the temporary undo, and these segments are called

temporary undo segments

.

Enabling and Disabling Temporary Undo

You can enable or disable temporary undo for a session or for the system. To do so, set the

TEMP_UNDO_ENABLED

initialization parameter.

16.7.1

About Managing Temporary Undo

Temporary undo records are stored in the database's temporary tablespaces and thus are not logged in the redo log. When temporary undo is enabled, some of the segments used by the temporary tablespaces store the temporary undo, and these segments are called

temporary undo segments

.

When temporary undo is enabled, it might be necessary to increase the size of the temporary tablespaces to account for the undo records.

Enabling temporary undo provides the following benefits:

Temporary undo reduces the amount of undo stored in the undo tablespaces.

Less undo in the undo tablespaces can result in more realistic undo retention period requirements for undo records.

Temporary undo reduces the size of the redo log.

Performance is improved because less data is written to the redo log, and components that parse redo log records, such as LogMiner, perform better because there is less redo data to parse.

Temporary undo enables data manipulation language (DML) operations on temporary tables in a physical standby database with the Oracle Active Data Guard option. However, data definition language (DDL) operations that create temporary tables must be issued on the primary database.

You can enable temporary undo for a specific session or for the whole system. When you enable temporary undo for a session using an

ALTER

SESSION

statement, the session creates temporary undo without affecting other sessions. When you enable temporary undo for the system using an

ALTER

SYSTEM

statement, all existing sessions and new sessions create temporary undo.

When a session uses temporary objects for the first time, the current value of the

TEMP_UNDO_ENABLED

initialization parameter is set for the rest of the session. Therefore, if temporary undo is enabled for a session and the session uses temporary objects, then temporary undo cannot be disabled for the session. Similarly, if temporary undo is disabled for a session and the session uses temporary objects, then temporary undo cannot be enabled for the session.

Temporary undo is enabled by default for a physical standby database with the Oracle Active Data Guard option. The

TEMP_UNDO_ENABLED

initialization parameter has no effect on a physical standby database with Active Data Guard option because of the default setting.

Note:

Temporary undo can be enabled only if the compatibility level of the database is 12.0.0 or higher.

See Also:

16.7.2

Enabling and Disabling Temporary Undo

You can enable or disable temporary undo for a session or for the system. To do so, set the

TEMP_UNDO_ENABLED

initialization parameter.

To enable or disable temporary undo:

In SQL*Plus, connect to the database.

If you are enabling or disabling temporary undo for a session, then start the session in SQL*Plus.

If you are enabling or disabling temporary undo for the system, then connect as an administrative user with the

ALTER

SYSTEM

system privilege in SQL*Plus.

Set the

TEMP_UNDO_ENABLED

initialization parameter:To enable temporary undo for a session, run the following SQL statement:

ALTER SESSION SET TEMP_UNDO_ENABLED = TRUE;

To disable temporary undo for a session, run the following SQL statement:

ALTER SESSION SET TEMP_UNDO_ENABLED = FALSE;

To enable temporary undo for the system, run the following SQL statement:

ALTER SYSTEM SET TEMP_UNDO_ENABLED = TRUE;

After temporary undo is enabled for the system, a session can disable temporary undo using the

ALTER

SESSION

statement.

To disable temporary undo for the system, run the following SQL statement:

ALTER SYSTEM SET TEMP_UNDO_ENABLED = FALSE;

After temporary undo is disabled for the system, a session can enable temporary undo using the

ALTER

SESSION

statement.

You can also enable temporary undo for the system by setting

TEMP_UNDO_ENABLED

to

TRUE

in a server parameter file or a text initialization parameter file. In this case, all new sessions create temporary undo unless temporary undo is disabled for the system by an

ALTER

SYSTEM

statement or for a session by an

ALTER

SESSION

statement.

See Also:

Oracle Database Reference

for more information about the

TEMP_UNDO_ENABLED

initialization parameter

Oracle Data Guard Concepts and Administration

for information about enabling and disabling temporary undo in an Oracle Data Guard environment

TEMP_UNDO_ENABLED

TEMP_UNDO_ENABLED

determines whether transactions within a particular session can have a temporary undo log.

Property

Description

Parameter type

Boolean

Default value

false

Modifiable

ALTER SESSION

,

ALTER SYSTEM

Modifiable in a PDB

Yes

Range of values

true | false

Basic

No

Oracle RAC

Each session of each instance can have its own value or not set any value at all

The default choice for database transactions has been to have a single undo log per transaction. This parameter, at the session level / system level scope, lets a transaction split its undo log into temporary undo log (for changes on temporary objects) and permanent undo log (for changes on persistent objects).

By splitting the undo stream of a transaction into two streams (temporary and permanent), a database can provide separate storage and retention model for these. This results in overall reduction in the size of undo log and redo log in the database

If database applications make use of temporary objects (using global temporary tables or temporary table transformations), it is advisable to set this parameter's value to

true

.

When

TEMP_UNDO_ENABLED

is set to

true

and the COMPATIBLE initialization parameter is set to

12.0.0

, this feature is enabled. The temporary undo feature is enabled for the session in which it is set. Setting it across the system will affect all existing and upcoming sessions. If the value is set in the

init.ora

file, all upcoming sessions will inherit this value unless overwritten by an explicit ALTER SESSION or ALTER SYSTEM statement. All undo for operations on temporary objects is deemed temporary.

If

TEMP_UNDO_ENABLED

is not set to

true

, existing applications that make use of temporary objects run as is without any change.

Once the value of the parameter is set, it cannot be changed for the lifetime of the session. If the session has temporary objects using temporary undo, the parameter cannot be disabled for the session. Similarly, if the session already has temporary objects using regular undo, setting this parameter will have no effect.

This parameter is only applicable for the primary database. For a standby database, this parameter is ignored because temporary undo is enabled by default on the standby database.

oracle 12c undo,Oracle 12c 新特性之临时Undo--temp_undo_enabled相关推荐

  1. 解读Tom介绍的Oracle Database 12c的12个新特性

    在OOW 2012上Tom kyte介绍了Oracle新一代重量级数据库产品12c 的12个新特性, 目前Open World 2012的主要PDF都可以下载了,传送门在此:Search Conten ...

  2. atitit.Oracle 9 10 11 12新特性attilax总结

    atitit.Oracle 9  10 11  12新特性 1. ORACLE 11G新特性 1 1.1. oracle11G新特性 1 1.2. 审计 1 1.3. 1.   审计简介 1 1.4. ...

  3. 今天聊聊Oracle Database 21c 十“小”新特性

    墨墨导读:Oracle Database 21c 已经在云上提供,线下版本将于2021年上半年提供,这标志着 Oracle 进入了下一个版本周期的创新发布. 关于 Oracle 21c 其实就相当于 ...

  4. 嘉年华回顾丨 杨长老带你解密 Oracle 19c 和 20c 的新特性

    2020年数据技术嘉年华还有两周多的时间,相信大家期待值也越来越高.数据技术嘉年华组委会在此精心为大家准备了"嘉年华回顾",挑选往届大会中热门的演讲.小编带大家回顾往届的高光时刻! ...

  5. 深入解析 | Oracle Database 20c 十大新特性一览

    在2020年2月14日,Oracle 正式宣布在 Oracle Cloud 发布 Database 20c 的预览版,同时发布了所有的官方文档. 为了和大家及时分享关于 Oracle 20c 引人瞩目 ...

  6. 开工大吉:Oracle 18c已经发布及新特性介绍

    在2018的新年(据2月16日文章),Oracle宣布Database 18c已经发布,但是仍然是首先在Oracle Cloud上一体机环境发布出来.所以要等到常规版本的公开提供,还有一段时间要等. ...

  7. Oracle 12c 新特性之 temp undo

    Oracle 12c R1 之前,临时表生成的undo记录是存储在undo表空间里的,通用表和持久表的undo记录也是类似的.而在 12c R12 的临时 undo 功能中,临时 undo 记录可以存 ...

  8. 入微:探究文档中找不到的12c并行索引扫描新特性

    杨廷琨,网名 yangtingkun 云和恩墨技术总监,Oracle ACE Director,ACOUG 核心专家 Oracle在12c之前对于索引范围扫描是没有办法并行执行的,从12.1开始,Or ...

  9. oracle 10g delete flashback,10g新特性,flashback系列 来自piner

    一 Flashback database falshback database是采用日志 falsgback drop是采用表空间的空间 其它的都是与undo有关... fashback是我对10g一 ...

最新文章

  1. 01_Nginx安装,nginx下部署项目,nginx.conf配置文件修改,相关文件配置
  2. TextView的部分点击事件和点击事件
  3. 石锤!今年Python要过苦日子了? 程序员:我疯了!
  4. SLAM研究内容框架分析
  5. 单例模式 c# 1214
  6. Java常用JSON库FastJson,Gson,Jackson,Json-lib性能及特点比较,常用工具方法
  7. 理发店收银系统php,理发店收银系统优缺点
  8. Windows读写硬盘
  9. 谈谈时间序列的平稳性
  10. LayoutInflater 总结
  11. 西游记不单单讲的是故事(1) ------ 摘自 吴闲云的《煮酒探西游》
  12. python分割文件_python简单分割文件的方法
  13. 2015伦敦深度学习峰会笔记:来自DeepMind、Clarifai等大神的分享
  14. B. Ternary String
  15. 基于三相VSR的SVPWM调制
  16. 前端处理后端返回的excel文件流并下载
  17. Teach repeat replan 安装中遇到的问题记录
  18. 路由器VRF多个虚拟路由器测试
  19. 免激活Vista并合法使用1年的方法
  20. Appium-实现手势密码登陆

热门文章

  1. 唯美的古风句子 惊艳。。。。。
  2. js css 特效网站收藏
  3. c4d打开没反应_提升C4D渲染速度,你需要的高端显卡选购指南
  4. 矢量图形SVG高级动画
  5. 纸的折法(包括:枫叶,梅花,千纸鹤,小狗,豹子,蛇,大象,狐狸,鹅,老鼠,猴子,骆驼,蜻蜓,蝎子,瓢虫,螳螂,蜜蜂,船和小猫咪)...
  6. 哈佛大学用4张图,说透了情商与幸福
  7. shardingsphere配置id生成策略无效
  8. 2015 年下半年 网络管理员 下午试卷
  9. 【luogu CF1693D】Decinc Dividing(DP)
  10. JS中单击多次执行一次的问题