【脚本】Resumable Space Allocation Example

本文介绍如何使用 Oracle 的 RESUMABLE 特性避免因空间不足导致的事务回滚。包括授予用户 resumable 权限、设置会话为可恢复状态、查看 DBA_RESUMABLE 视图获取会话挂起原因、解决空间配额问题及取消可恢复事务等步骤。
Resumable Space Allocation Example
Using RESUMABLE Session to Avoid Transaction Abort Due to Space Errors [ID 136941.1]

1. The user running the transaction requires the RESUMABLE system privilege:

SQL> conn system/oracle
Connected.

SQL> grant resumable to scott;
Grant succeeded.

 

resumable权限也被包含在其role里面,比如dba,当一个用户拥有dba role时,就自动拥有了resumable privilege.

 

2. Set the session so that the following transactions might be resumed in case of interruption due to space allocation:

 SQL> alter session enable resumable;
 Session altered.

 

This can be set automatically through anAFTER LOGON trigger.
    --也可以通过触发器来自动设置

  SQL> create or replace trigger logon_set_resumable
    2  after logon
    3  on scott.schema
    4  begin
    5  	execute immediate 'alter session enable resumable timeout 1200';
    6  end;
    7  /
 
  Trigger created.

 
 3. While inserting newrows into TEST_RESUMABLE table, the user session hangs,but the transaction doesnot roll back:

The DBA can retrieve(得到;取到) the reason why the session of user SCOTT hangs in DBA_RESUMABLE view:
 
3.1 Displaying the DBA_RESUMABLE view:

   SQL> select user_id,SESSION_ID, STATUS, START_TIME, SUSPEND_TIME,
     2         SQL_TEXT, ERROR_NUMBER, ERROR_MSG
     3  from dba_resumable;
      USER_ID SESSION_ID STATUS    START_TIME           SUSPEND_TIME
   ---------- ---------- --------- -------------------- --------------------
   SQL_TEXT
   -------------------------------------------------------------------------
   ERROR_NUMBER
   ------------
   ERROR_MSG
   -------------------------------------------------------------------------
           54          9 SUSPENDED 03/14/01 10:49:25    03/14/01 11:14:17
   insert into test_resumable select * from test_resumable
           1631
   ORA-01631: max # extents (5) reached in table SCOTT.TEST_RESUMABLE

 
3.2 In alert.log file:

     Wed Mar 14 11:14:17 2001
     statement in resumable session 'User SCOTT(54), Session 9, Instance 1'was suspended due to ORA-01631: max # extents (5) reached in table SCOTT.TEST_RESUMABLE

 
3.3 The statement may issue the following error when the timeout set for the session has expired:
 

      SQL> insert into test_resumable values (1);
      insert into test_resumable values (1)
               *
      ERROR at line 1:
      ORA-30032: the suspended (resumable) statement has timed out
      ORA-01536: space quota exceeded for tablespace 'EXAMPLE'

 

 

3.4 The DBA now knows why the session hangs, and needs to find which action to take to alleviate the ora-01536 error:

   SQL>  connect system/manager
   Connected.
   SQL> alter table scott.test_resumable storage (max extents 8);
   Table altered.

 
In alert.log file:

      Wed Mar 14 11:24:02 2001
      statement in resumable session 'User SCOTT(54), Session 9, Instance 1' 
      was resumed and no more errors in DBA_RESUMABLE view:
   SQL>select user_id,SESSION_ID, STATUS, START_TIME, RESUME_TIME,
     2         SQL_TEXT, ERROR_NUMBER, ERROR_MSG
     3  from dba_resumable;
 
      USER_ID SESSION_ID STATUS    START_TIME           RESUME_TIME  
   ---------- ---------- --------- -------------------- --------------------
   SQL_TEXT
   -------------------------------------------------------------------------
   ERROR_NUMBER
   ------------
   ERROR_MSG
   -------------------------------------------------------------------------
           54          9 NORMAL    03/14/01 10:49:25    03/14/01 11:24:02
   insert into test_resumable select * from test_resumable
              0
 

  

   While the status is NORMAL or the error_number is 0, the resumable statements keep on working correctly unless the timeout is expired.
   This also means that there are sessions set in resumable state.
   As soon as an error_number <> 0 appears, then a resumable session has encountered a space allocation issue.
 
Note:
   The DBA can cancel the resumable transaction by aborting the session by the procedure DBMS_RESUMABLE.ABORT(sid#). An ORA-1013 "user requested cancel of current operation" is returned to the user.

 

3.5 If the session does not need to be in resumable state, the session can disable the resumable state:

   SQL> alter session disable resumable;
   Session altered.
 
   SQL> select user_id,SESSION_ID, STATUS, START_TIME, RESUME_TIME,
     2         SQL_TEXT, ERROR_NUMBER, ERROR_MSG
     3  from dba_resumable;
 
   no rows selected

 
3.6 Other space errors that suspend transactions
-------------------------------------------------------------------
***
statement in resumable session 'User SCOTT(54), Session 9, Instance 1' was suspended due to ORA-01536: space quota exceeded for tablespace 'EXAMPLE'
 
***
statement in resumable session 'User SCOTT(54), Session 8, Instance 1' was suspended due to ORA-01562: failed to extend rollback segment number 11
 
***
statement in resumable session 'User SCOTT(54), Session 8, Instance 1' was suspended due to ORA-01628: max # extents (2) reached for rollback segment RS01 FULL status of rollback segment 11 set
 
***
statement in resumable session 'User SCOTT(54), Session 9, Instance 1' was suspended due to ORA-01631: max # extents (2) reached in table SCOTT.TEST_RESUMABLE 
 
***
statement in resumable session 'User SYSTEM(5), Session 8, Instance 1' was suspended due to ORA-01652: unable to extend temp segment by 32 in tablespace TEMP_TS 
 
***
statement in resumable session 'User SCOTT(54), Session 9, Instance 1' was suspended due to ORA-01653: unable to extend table SCOTT.TEST_RESUMABLE by 256 in tablespace USERS 
 
***
statement in resumable session 'User SCOTT(34), Session 8, Instance 1' was suspended due to ORA-01654: unable to extend index SCOTT.SYS_IOT_TOP_27956 by 8 in tablespace PERM_DICT_2K
 
***
statement in resumable session 'User SYSTEM(5), Session 11, Instance 1' was suspended due to ORA-01658: unable to create INITIAL extent for segment in tablespace LMT_1
 
***
statement in resumable session 'User SYSTEM(5), Session 11, Instance 1' was suspended due to ORA-01659: unable to allocate MINEXTENTS beyond 42 in tablespace LMT_1
 
3.7 Other messages in alert.log:
***
Wed Mar 14 10:43:52 2001
statement in resumable session 'User SCOTT(54), Session 9, Instance 1' was aborted

 

 

### 可恢复错误及其解决方案 #### Oracle 中的可恢复语句机制概述 Oracle 数据库提供了一种称为“可恢复语句”的特性,允许长时间运行的操作在遇到特定类型的资源不足时被挂起并稍后继续执行。当数据库实例检测到某些条件(如空间不足)阻止操作完成时,会触发此功能。 对于提到的具体情况,在导入表数据对象过程中遇到了超时问题以及无法扩展回滚段的情况[^2]: - **ORA-31693**: 表明由于某个原因导致加载/卸载失败,并且该过程已被跳过。 - **ORA-30032 和 ORA-30036** 组合提示了一个典型的场景——即存在未决状态下的 SQL 语句因为等待时间超过设定阈值而终止;同时指出尝试增加undo tablespace中的segment大小也遭遇了障碍。 针对上述情形可以采取如下措施来解决 resumable error: 1. **调整参数设置** 修改 `RESUMABLE_TIMEOUT` 参数以延长默认等待时限,从而给予更多的时间让管理员解决问题后再自动重试。可以通过以下命令实现: ```sql ALTER SYSTEM SET RESUMABLE_TIMEOUT=3600; ``` 2. **监控与管理挂起点** 使用视图 `V$SESSION_WAIT` 或者专用工具包 DBMS_RESUMABLE 来跟踪当前存在的任何处于暂停状态的任务,并获取有关这些事件的信息以便及时处理潜在瓶颈。 3. **确保足够的 Undo Tablespace 容量** 鉴于报错显示 undo space 不足,需确认是否有充足的可用磁盘配额分配给对应的 UNDO 表空间。如果确实面临存储压力,则考虑扩充现有容量或是创建新的 UNDO 文件加入集群配置之中。 4. **优化作业调度策略** 如果可能的话重新规划大体积 DML 操作的日程安排避开高峰时段减少并发冲突的可能性进而降低因竞争引发的各种异常状况的发生几率。 通过实施以上建议能够有效缓解乃至消除由 resumable errors 所带来的负面影响,保障业务连续性和稳定性的同时提高整体性能表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值