[转帖]11G Undo使用率很高问题

纵饮孤独 提交于 2019-12-02 21:09:35

11G Undo使用率很高问题

http://blog.itpub.net/12679300/viewspace-1164916/

 

原创 Oracle 作者:wzq609 时间:2014-05-20 10:23:29  2623  0

事件背景:

      公司的ERP数据库是11.2.0.3的版本,最近观察到一个奇怪的现象就是数据库的UNDO表空间的使用率一直居高不下;UNDO表空间的大小为76G,但是使用率一直保持着70%以上。

     趁此机会又重新学习了一遍Undo的知识,最终解决了这个问题,以下是解决过程中整理的文档。(以下都是从Oracle联机文档里面找到的)

 

一、What Is Undo?Oracle Database creates and manages information that is used to roll back, or undo, changes to the database. Such information consists of records of the actions of transactions, primarily before they are committed. These records are collectively referred to as undo.Undo records are used to:Roll back transactions when a ROLLBACK statement is issued  ------用于事务的回滚Recover the database                                                                       ------用于数据库的恢复Provide read consistency                                                                -------提供读一致性Analyze data as of an earlier point in time by using Oracle Flashback Query   -----用于数据库的闪回查询Recover from logical corruptions using Oracle Flashback features                   -----通过闪回恢复数据库的逻辑错误When a ROLLBACK statement is issued, undo records are used to undo changes that were made to the database by the uncommitted transaction. During database recovery, undo records are used to undo any uncommitted changes applied from the redo log to the data files. Undo records provide read consistency by maintaining the before image of the data for users who are accessing the data at the same time that another user is changing it.

二、影响UNDO的几个参数

通过语句show parameter undo,可以找到影响Undo表空间的三个参数

 1、_in_memory_undo

了解ORACLE参数设计的高手一看就知道_in_memory_undo,前面有"_"参数是ORACLE的隐藏参数;

参考链接:http://www.hellodba.com/reader.php?ID=31&lang=CN  

有兴趣的朋友可以深入研究。

 

2、undo_management

Property

Description

Parameter type

String

Syntax

UNDO_MANAGEMENT = { MANUAL | AUTO }

Default value

AUTO

Modifiable

No

Basic

No

Oracle RAC

Multiple instances must have the same value. 

UNDO_MANAGEMENT specifies which undo space management mode the system should use. When set to AUTO, the instance starts in automatic undo management mode. In manual undo management mode, undo space is allocated externally as rollback segments

undo的管理其实也是Oracle数据库管理进步的一个见证,早期的oracle的undo的管理都是手动的,随着软件的发展undo的管理变成自动,专业名词 AUM(Automatic UndoManagement),该技术为DBA又减轻了不少工作(DBA的工作越来越少了,也不知道是好事还是坏事)。

 

3、 AUM(Automatic UndoManagement)说明

     Oracle providesa fully automated mechanism, referred to as automatic undo management, formanaging undo information and space. With automatic undo management, thedatabase manages undo segments in an undo tablespace. Beginning with Release11g, automatic undo management is the default mode for a newly installeddatabase. An auto-extending undo tablespace named UNDOTBS1 isautomatically created when you create the database with Database ConfigurationAssistant (DBCA).    Oracle 使用了一个完全自动的机制:AUM 来管理undo 的信息和空间。使用AUM之后,数据库在undo表空间里管理undo segments。从Oracle 11g开始,新建的数据库默认就是用AUM。在使用DBCA 创建实例时,会自动创建一个自动扩展的UNDO表空间:UNDOTBS1. When theinstance starts, the database automatically selects the first available undotablespace. If no undo tablespace is available, the instance starts without anundo tablespace and stores undo records in the SYSTEM tablespace.This is not recommended, and an alert message is written to the alert log fileto warn that the system is running without an undo tablespace.       当启动实例时,db 会自动选择第一个可用的undo 表空间,如果没有undo 表空间可用,那么实例也会启动,但这种情况undo 记录是存在SYSTEM 表空间的rollback segment里,这种情况是不推荐使用,并且在使用SYSTEM 表空间时,alert log里也会出现警告信息,说没有使用undo 表空间。   如果undo 表空间是自动扩展的,那么数据会尝试使用UNDO_RETENTION 参数,如果表空间不足时,不会去重写没有过期(仅仅是没有过期的committed的数据)的undo数据,而是会自动扩展undo 表空间。当undo 表空间扩展达到MAXSIZE值时,数据库开始重写没有过期的undo 数据。

   

4.Undo Retention Period 说明

    After atransaction is committed, undo data is no longer needed for rollback ortransaction recovery purposes. However, for consistent read purposes,long-running queries may require this old undo information for producing olderimages of data blocks. Furthermore, the success of several Oracle Flashbackfeatures can also depend upon the availability of older undo information. Forthese reasons, it is desirable to retain the old undo information for as longas possible.         事务提交之后,UNDO 数据就不需要用来rollback 或者事务恢复,但是为了一致性读,比如long-runing的查询可能还是需要这些旧的undo 数据来获取block的前镜像。此外,Flashback的特性也会受undo信息的影响,因为这些原因,旧的undo 信息还是需要尽可能的长。     When automaticundo management is enabled, there is always a current undo retention period, which is the minimum amount of time that Oracle Database attempts toretain old undo information before overwriting it. Old (committed) undoinformation that is older than the current undo retention period is said to be expired andits space is available to be overwritten by new transactions. Old undoinformation with an age that is less than the current undo retention period issaid to be unexpired and is retained for consistent read and OracleFlashback operations.         当启用AUM后,就会涉及到undo retention period,其是保存最小的undo信息的时间。 Old undo 信息(已经committed)如果超过了这个retentionperiod,那么其就会被标记为expiered,对应的空间也可以被其他的事务重写。     Oracle Databaseautomatically tunes the undo retention period based on undo tablespace size andsystem activity. You can optionally specify a minimum undo retention period (inseconds) by setting the UNDO_RETENTION initialization parameter.    Oracle 会根据undo 表空间的大小和系统的活动情况自动调整undoretention period的时间。我们也可以手动在初始化参数里修改UNDO_RETENTION参数,该参数单位是秒。  Theexact impact this parameter on undo retention is as follows:--关于这个参数的2点说明:(1)    The UNDO_RETENTION parameteris ignored for a fixed size undo tablespace. The database always tunes the undoretention period for the best possible retention, based on system activity andundo tablespace size.--如果UNDO 表空间的大小是固定的,即不可自动扩展,那么在这种情况下,UNDO_RETENTION参数是会自动忽略,不会生效,数据库根据系统活动情况和undo表空间大小来调整undo retention period为最佳值。 (2)    For an undo tablespace with the AUTOEXTEND optionenabled, the database attempts to honor the minimum retention period specifiedby UNDO_RETENTION. When space is low, instead of overwriting unexpired undoinformation, the tablespace auto-extends. If the MAXSIZE clause isspecified for an auto-extending undo tablespace, when the maximum size isreached, the database may begin to overwrite unexpired undo information. The UNDOTBS1 tablespacethat is automatically created by DBCA is auto-extending.--如果undo 表空间是自动扩展的,那么数据会尝试使用UNDO_RETENTION 参数,如果表空间不足时,不会去重写没有过期(仅仅是没有过期的committed的数据)的undo数据,而是会自动扩展undo 表空间。当undo 表空间扩展达到MAXSIZE值时,数据库开始重写没有过期的undo 数据。 (3)   Undo Retention Tuning and Alert ThresholdsFor a fixed-sizeundo tablespace, the database calculates the best possible retention based ondatabase statistics and on the size of the undo tablespace. For optimal undomanagement, rather than tuning based on 100% of the tablespace size, thedatabase tunes the undo retention period based on 85% of the tablespace size,or on the warning alert threshold percentage for space used, whichever islower. (The warning alert threshold defaults to 85%, but can be changed.)Therefore, if you set the warning alert threshold of the undo tablespace below85%, this may reduce the tuned size of the undo retention period.--对于固定大小的undo tablespace,数据库根据统计信息和undo 表空间的大小来计算最佳的retention. 管理undo最理想的情况,不是根据100%的undo表空间来计算,而是根据undo 表空间的85%来计算,或者设置的空间警告值来计算,默认情况下空间警告值是85%。 

 

总结:从ORACLE 11G开始数据库Undo表空间都是通过自动管理的方式进行的,影响Undo表空间的使用率会有Undo Retention和数据文件的管理方式,当数据文件设置成不可扩展的时候UNDO_RETENTION参数是会自动忽略,数据库根据系统活动情况和undo表空间大小来调整undo retention period为最佳值,一般会在50%以上;

当数据文件的参数是可扩展的时候,会根据UNDO_RETENTION设置的时间去决定数据是否过期,当数据的保留时间超过了该参数那么这些在undo里面就失效了,会被重写;

在本系统中打开数据文件的自动扩展功能,并把数据文件的扩展大小和数据文件本身的大小设置成一样,经过一天时间的运行发现数据库的undo表空间的使用率明显的降下来了,在10%以下;

 

...............................................................................................................................................................................................................

ORACLE技术博客:ORACLE 猎人笔记               数据库技术群:367875324 (请备注ORACLE管理 )  

...............................................................................................................................................................................................................................

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!