【理论】Oracle Resumable Space Allocation

Oracle Resumable Space Allocation

1.About Oracle Resumable Space Allocation

      从Oracle9i版本开始,Oracle提供了一种避免因为space Error而导致事务异常的机制: resumable space allocation. Oracle 10gOCP考试中有考resumable session的这个知识点。

官网对Resumable的解释如下:

Oracle Documents 写道
Advantage is for DBAs who are running yearly reports and do not know how much extra disk space is required for TEMP, UNDO or DATA tablespaces in order to complete the job.This functionality does not break the job, but raises an alert for the DBA to fix the issue. The job automatically resumes once the DBA has fixed the issue.

      当我们执行一个事务操作,如果使用了resumable space allocation,那么如果遇到space空间不够的情况,事务不会中断,而是生成一条alert log 发送给DBA,当DBA 解决这个问题之后,事务自动恢复运行。 

在Oracle 10g中对resumable session功能做了增强,这些新特性在MOS的文档上有说明:

10g NEW FEATURE on RESUMABLE TIMEOUT [ID 240991.1].10g中增强的内容有:

 

1)增加了一个resumable_timeout的参数

    

     该参数在system和session level级均可以修改。对RAC DB而言,每个instance可以单独设置。而9i中只能在session一级中设置。

Oracle Documents 写道
A resumable operation is suspended whenever it encounters some space issue. (See Database Administrator's Guide for information about enabling resumable space allocation, what conditions are resumable, and what statements can be made resumable. For example,DEAD LOCK or ORA-00600 error are not resumable situations).

Once the operation is suspended, an alert message is sent to the DBA. Once the cause that caused the failure is fixed, the suspended statement automatically resume sits execution. Every "resumable" operation has a time-out period associated. The default value of the time-out period is 2 hours (unless the user issues an alter session enable resumable). A suspended operation is automatically aborted if the error condition is not fixed within the "time-out".
 

      设置resumable_timeout之后,在指定的timeout 时间内会自动恢复,如果超过这个时间没有解决问题,事务操作还是会被中断。

 

2)对分布式事务的支持

Oracle Documents 写道
Distributed Transactions Behavior Supported In 9i, users are not allowed to start a distributed transaction in a resumable enabled session. And if a session has a distributed transaction, users are not allowed to enable resumable.

These restrictions are removed in 10g. However, in a distributed transaction, if users enable/disable resumable or change resumable_timeout, only the local instances are affected. In a distributed transaction, sessions on remote instances are suspended if resumable has been enabled in the remote instance.
 

3)增加了一个监控的视图

     在10g中,我们也可以通过DBA_OUTSTANDING_ALERTS来监控resumable session。

 

2. Official Notification Managing Resumable

     Oracle 11g R2官方针对Managing Resumable Space Allocation 的说明如下:

Oracle Documents 写道
Oracle Database provides a means for suspending, and later resuming, the execution of large database operations in the event of space allocation failures. Therefore, you can take corrective action instead of the Oracle Database server returning an error to the user. After the error condition is corrected, the suspended operation automatically resumes. This feature is called resumable space allocation. The statements that are affected are called resumable statements.

 

2.1 Resumable Space Allocation Overview

     This sectionprovides an overview of resumable space allocation. It describes how resumable space allocation works, and specifically defines qualifying statements and error conditions.

 

2.1.1 How Resumable Space Allocation Works

     The following is an overview of how resumable space allocation works. Details are contained inlater sections.

 

1. A statementexecutes in a resumable mode only if its session has been enabled for resumablespace allocation by one of the following actions:

    --启动session 的resumable space allocation,相关的2个actions:

1)The RESUMABLE_TIMEOUT initialization parameter is set to a non zero value.

2)The ALTER SESSION ENABLE RESUMABLE statement is issued.

 

2. A resumable statement is suspended when one of the following conditions occur (these conditions result in corresponding errors being signalled for non-resumablestatements):

    --在启动resumable session之后,当发生以下情况,resumable的语句就会被suspend挂起

1)Out of space condition

2)Maximum extents reached condition

3)Space quota exceeded condition.

 

3.When the execution of a resumable statement is suspended, there are mechanisms to perform user supplied operations, log errors, and to query the status of the statementexecution. When a resumable statement is suspended the following actions aretaken:

    --当resumable的statement 被suspend,那么相关的机制会执行,如生成log信息。具体的log 有如下3类:

1)The error is reported in the alert.log.

2)The system issues the Resumable Session Suspended alert.

3)If the user registered a trigger on the AFTER SUSPEND system event, the user trigger is executed. A user supplied PL/SQL procedure can access the error message data using the DBMS_RESUMABLE package and the DBA_ or USER_RESUMABLE view.

 

4.Suspending astatement automatically results in suspending the transaction. Thus all transactionalresources are held through a statement suspend and resume.

    --suspend的事物自动转到suspend事务中,并且事务所有相关的资源都会通过suspend 和 resume 被hold。

 

5.When the errorcondition is resolved (for example, as a result of user intervention or perhapssort space released by other queries), the suspended statement automaticallyresumes execution and the Resumable Session Suspended alert is cleared.

    --当error 被解决之后,被suspend的statement会自动的执行,resumable session的suspended alert 也会自动清除 。

 

6.A suspended statement can be forced to throw the exception using the DBMS_RESUMABLE.ABORT() procedure.This procedure can be called by a DBA, or by the user who issued the statement.

    --suspend 的statement 也可以使用DBMS_RESUMABLE.ABORT()过程来强制中断。

 

7.A suspensiontime out interval is associated with resumable statements. A resumablestatement that is suspended for the timeout interval (the default is two hours)wakes up and returns the exception to the user.

    --suspension time的设置resumable的时间相关,该参数的默认值是2个小时,即如果在2个小时以后错误尚未解决,resumable 的session wakeup,那么就会中断并反馈异常给终端用户

 

8.A resumablestatement can be suspended and resumed multiple times during execution.

    --resumable statement 在执行时可以被多次suspend 和 resume。

 

2.1.2 What Operations are Resumable?

The following operations are resumable:

1. Queries

Oracle Documents 写道
SELECT statements that run out of temporary space (for sort areas) are candidates for resumable execution. When using OCI(Oracle Call Interface), the calls OCIStmtExecute() and OCIStmtFetch() are candidates.

 2. DML

Oracle Documents 写道
INSERT, UPDATE,and DELETE statements are candidates. The interface used to execute them does not matter; it can be OCI, SQLJ, PL/SQL, or another interface. Also, INSERT INTO...SELECT from external tables can be resumable.

3. Import/Export

Oracle Documents 写道
As for SQL*Loader, a command line parameter controls whether statements are resumable after recoverable errors.

4. DDL

The following statements are candidates for resumable execution:

Oracle Documents 写道
(1)CREATE TABLE ... AS SELECT
(2)CREATE INDEX
(3)ALTER INDEX ... REBUILD
(4)ALTER TABLE ... MOVE PARTITION
(5)ALTER TABLE ... SPLIT PARTITION
(6)ALTER INDEX ... REBUILD PARTITION
(7)ALTER INDEX ... SPLIT PARTITION
(8)CREATE MATERIALIZED VIEW
(9)CREATE MATERIALIZED VIEW LOG
 

2.1.3 What Errors are Correctable?

     There are three classes of correctable errors: 

1. Out of space condition

     The operation can not acquire any more extents for a table/index/temporary segment /undo segment/cluster/LOB/table partition/index partition in a tablespace. For example, the following errors fall in this category:

     ORA-01653 unable to extend table ... in tablespace ...

     ORA-01654 unable to extend index ... in tablespace ...

2. Maximum extents reached condition

     The number of extents in a table/index/temporary segment/undo segment /cluster /LOB /table partition /index partition equals the maximum extents defined on the object. For example, the following errors fall in this category:

     ORA-01631 max #extents ... reached in table ...

     ORA-01632 max #extents ... reached in index ...

3. Space quota exceeded condition

     The user has exceeded his assigned space quota in the tablespace. Specifically, this is noted by the following error:

     ORA-01536 space quota exceeded for tablespace string

 

2.1.4 Resumable Space Allocation and Distributed Operations

     In a distributed environment, if a user enables or disables resumable space allocation, or if you, as a DBA, alter the RESUMABLE_TIMEOUT initialization parameter,only the local instance is affected. In a distributed transaction, sessions or remote instances are suspended only if RESUMABLE has been enabled in the remote instance.

    --在distributed environment中,resumable的配置只对本地的实例有效,如果要在远程实例上生效就需要在远程实例上配置。

 

2.1.5 Parallel Execution and Resumable Space Allocation

Oracle Documents 写道
In parallel execution, if one of the parallel execution server processes encounters a correctable error, that server process suspends its execution. Other parallel execution server processes will continue executing their respective tasks,until either they encounter an error or are blocked (directly or indirectly) by the suspended server process. When the correctable error is resolved, the suspended process resumes execution and the parallel operation continues execution. If the suspended operation is terminated, the parallel operation aborts, throwing the error to the user.

 

    --对于并行执行,如果其中的一个parallel execution 进程遇到了correctable error,那么其对应的server process 就会被suspend,其它的parallel 进程继续执行,直到它们遇到error 或者被suspend进程block。当correctable error 被解决后,suspend 进程会被重新执行。如果suspend操作被中断,那么对应的并行操作也会被中断,然后抛出错误给用户。

Oracle Documents 写道
Different parallel execution server processes may encounter one or more correctable errors. This may result in firing an AFTER SUSPEND trigger multiple times, in parallel. Also, if a parallel execution server process encounters a non-correctable error while another parallel execution server process is suspended, the suspended statement is immediately aborted.

 

      不同的并行进程可能遇到一个或者多个correctable errors,这些错误可能导致触发AFTER SUSPEND 的触发器多次。当如果某个并行的进程遇到一个non-correctable error,而其它的并行进程是suspend,那么suspend 的事务就会被立即中断。

Oracle Documents 写道
For parallel execution, every parallel execution coordinator and server process has its own entry in the DBA_ or USER_RESUMABLE view.

      对于并行执行中的每个服务器进程,可以查看DBA_RESUMABLE 和 USER_RESUMABLE视图来获取相关的RESUMABLE信息。

 

2.2 Enabling and Disabling Resumable Space Allocation

 Oracle Documents 写道

Resumable space allocation is only possible when statements are executed within a session that has resumable mode enabled. There are two means of enabling and disabling resumable space allocation. You can control it at the system level with the RESUMABLE_TIMEOUT initialization parameter, or users can enable it at the session level using clauses of the ALTER SESSION statement.

    可以在系统级别或者session级别设置resumable space allocation。

Note:

     Because suspended statements can hold up some system resources, users must be granted the RESUMABLE system privilege before they are allowed to enable resumable space allocation and execute resumable statements.

    因为suspend 需要hold 一些系统资源,所有执行该操作的用户必须要先获取RESUMABLE的权限。

 

2.2.1 Setting the RESUMABLE_TIMEOUT Initialization Parameter

    --系统级别设置

     You can enable resumable space allocation system wide and specify a timeout interval by setting the RESUMABLE_TIMEOUT initialization parameter.

    --在系统级别设置需要在初始化参数里添加RESUMABLE_TIMEOUT参数。

     For example, the following setting of the RESUMABLE_TIMEOUT parameter in the initialization parameter file causes all sessions to initially be enabled for resumable space allocation and sets the timeout period to 1 hour

RESUMABLE_TIMEOUT  = 3600

    --这里设置timeout为1小时。

     If this parameter is set to 0, then resumable space allocation is disabled initially for all sessions. This is the default.

    --如果参数设置为0,则禁用resumable。默认情况就是0,即默认是禁用该功能的。

    You can use the ALTER SYSTEM SET statement to change the value of this parameter at the system level.

    --也可以使用alter system set 语句来进行设置。

Oracle Documents 写道
For example, the following statement will disable resumable space allocation for all sessions:
                               ALTER SYSTEM SET RESUMABLE_TIMEOUT=0;
Within a session, a user can issue the ALTER SESSION SET statement to set the RESUMABLE_TIMEOUT initialization parameter and enable resumable space allocation, change a timeout value, or to disable resumable mode.
 

2.2.2 Using ALTER SESSION to Enable and Disable Resumable Space Allocation

Oracle Documents 写道
A user can enable resumable mode for a session, using the following SQL statement:
                                   ALTER SESSION ENABLE RESUMABLE;
To disable resumable mode, a user issues the following statement:
                                   ALTER SESSION DISABLE RESUMABLE;
The default for a new session is resumable mode disabled, unless the RESUMABLE_TIMEOUT initialization parameter is set to a nonzero value.
The user can also specify a timeout interval, and can provide a name used to identify a resumable statement. These are discussed separately in following sections.

(1)Specifying a Timeout Interval

Oracle Documents 写道
A timeout period, after which a suspended statement will error if no intervention has taken place, can be specified when resumable mode is enabled. The following statement specifies that resumable transactions will time out and error after 3600 seconds:
                                         ALTER SESSION ENABLE RESUMABLE TIMEOUT 3600;
The value of TIMEOUT remains in effect until it is changed by another ALTER SESSION ENABLE RESUMABLE statement,it is changed by another means, or the session ends. The default timeout interval when using the ENABLE RESUMABLE TIMEOUT clause to enable resumable mode is 7200 seconds.

(2)Naming Resumable Statements

Oracle Documents 写道
Resumable statements can be identified by name. The following statement assigns a name to resumable statements:
          ALTER SESSION ENABLE RESUMABLE TIMEOUT 3600 NAME 'insert into table';
The NAME value remains in effect until it is changed by another ALTER SESSION ENABLE RESUMABLE statement, or the session ends. The default value for NAME is 'User username(userid), Session sessionid,Instance instanceid'.
The name of the statement is used to identify the resumable statement in the DBA_RESUMABLE and USER_RESUMABLE views.
 

2.2.3 Using a LOGON Trigger to Set Default Resumable Mode

Oracle Documents 写道
another method of setting default resumable mode, other than setting the RESUMABLE_TIMEOUT initialization parameter, is that you can register a database level LOGON trigger to alter a user's session to enable resumable and set a timeout interval.

    Note:

     If there aremultiple triggers registered that change default mode and timeout for resumablestatements, the result will be unspecified because Oracle Database does notguarantee the order of trigger invocation.

 

2.3 Detecting Suspended Statements

     When a resumablestatement is suspended, the error is not raised to the client. In order forcorrective action to be taken, Oracle Database provides alternative methods fornotifying users of the error and for providing information about thecircumstances.

    --当一个resumable 语句被suspend,这个error不会自动返回给用户,Oracle 提供一些方法来将这些error 信息通知用户。

 

2.3.1 Notifying Users: The AFTER SUSPEND System Event and Trigger

     When a resumablestatement encounter a correctable error, the system internally generates the AFTER SUSPEND system event. Users can registertriggers for this event at both the database and schema level. If a userregisters a trigger to handle this system event, the trigger is executed aftera SQL statement has been suspended.

    --当遇到correctable error 时,系统内部使用AFTER SUSPEND 触发器。 用户可以在DB 或者schema 级别注册这个触发器。 如果用户注册触发器来处理这个事件,那么触发器会在SQL 语句suspend 后执行。

 

     SQL statementsexecuted within a AFTER SUSPEND trigger arealways non-resumable and are always autonomous(有自主权的adj.. Transactions started within thetrigger use the SYSTEM rollback segment. These conditions are imposedto overcome deadlocks and reduce the chance of the trigger experiencing thesame error condition as the statement.

 

     Users can usethe USER_RESUMABLE or DBA_RESUMABLE views, or the DBMS_RESUMABLE.SPACE_ERROR_INFO function, within triggers to getinformation about the resumable statements.

    --在这个触发器中可以使用 USER_RESUMABLE , DBA_RESUMABLE 视图或者DBMS_RESUMABLE.SPACE_ERROR_INFO函数来获取更多的resumable 语句信息。

 

     Triggers canalso call the DBMS_RESUMABLE package to terminate suspended statements and modify resumable timeout values. In the following example, the default system timeout is changed by creating asystem wide AFTER SUSPEND trigger that calls DBMS_RESUMABLE toset the timeout to 3 hours:

    --在触发器中也可以调用 DBMS_RESUMABLE 包来中断suspended语句和修改resumable timeout 时间。

CREATE OR REPLACE TRIGGER resumable_default_timeout
AFTER SUSPEND
ON DATABASE
BEGIN
  DBMS_RESUMABLE.SET_TIMEOUT(10800);
END;
/
 

2.3.2 Using Views to Obtain Information About Suspended Statements

     The following views can be queried to obtain information about the status of resumablestatements:

 
 【理论】Oracle Resumable Space Allocation_第1张图片

 

2.3.3 Using the DBMS_RESUMABLE Package

     The DBMS_RESUMABLE packagehelps control resumable space allocation. The following procedures can beinvoked:

【理论】Oracle Resumable Space Allocation_第2张图片

 

 

2.4 Operation-Suspended Alert

         When a resumable session is suspended, an operation-suspended alert is issued on the object that needs allocation of resource for the operation to complete. Once the resource is allocated and the operation completes, the operation-suspended alert iscleared. See "Managing Tablespace Alerts" for more information on system-generatedalerts.

 

你可能感兴趣的:(oracle,RESUMABLE,space,Allocation)