`

【脚本】Registering an AFTER SUSPEND Trigger

阅读更多
Registering an AFTER SUSPEND Trigger

 

In the followingexample, a system wide AFTER SUSPEND trigger is created andregistered as user SYS at the database level. Whenever a resumablestatement is suspended in any session, this trigger can have either of twoeffects:

 

1If an undosegment has reached its space limit, then a message is sent to the DBA and the statement is aborted.

2If any otherrecoverable error has occurred, the timeout interval is reset to 8 hours.

Here are the statementsfor this example:

-- Hundsun@Askerain
--If the error is related to undo segments, log error, send email
--to DBA, and abort the statement. Otherwise, set timeout to 8 hours.
--
--sys.rbs_error is a table which is to be
--created by a DBA manually and defined as
--(sql_text VARCHAR2(1000), error_msg VARCHAR2(4000),
--suspend_time DATE)

  -- drop table sys.rbs_error avoid corruption
DROP TABLE sys.rbs_error;

  -- create table sys.rbs_error to record resumable error information
CREATE TABLE sys.rbs_error(sql_text VARCHAR2(1000),error_msg VARCHAR2(4000),suspend_time DATE);

  -- create a trigger to set strategies and report error information
CREATE OR REPLACE TRIGGER resumable_space_trigger
  AFTER SUSPEND ON DATABASE
  -- declare transaction in this trigger is autonomous
  -- this is not required because transactions within a trigger are always autonomous
DECLARE
     PRAGMA AUTONOMOUS_TRANSACTION;
     cur_sid           NUMBER;
     cur_inst          NUMBER;
     errno             NUMBER;
     err_type          VARCHAR2;
     object_owner      VARCHAR2;
     object_type       VARCHAR2;
     table_space_name  VARCHAR2;
     object_name       VARCHAR2;
     sub_object_name   VARCHAR2;
     error_txt         VARCHAR2;
     msg_body          VARCHAR2;
     ret_value         BOOLEAN;
     mail_conn        UTL_SMTP.CONNECTION;
BEGIN
     --Get session ID
     SELECT DISTINCT (SID) INTO cur_SID FROM V$MYSTAT;
     --Get instance number
     cur_inst := userenv('instance');
     --Get space error information
     ret_value := DBMS_RESUMABLE.SPACE_ERROR_INFO(err_type,object_type,object_owner,
                       table_space_name,object_name,sub_object_name);

  IF OBJECT_TYPE = 'UNDO SEGMENT' THEN        /* LOG ERROR */
         INSERT INTO sys.rbs_error(SELECT SQL_TEXT, ERROR_MSG, SUSPEND_TIME 
         FROM DBMS_RESUMABLE WHERE SESSION_ID = cur_sid AND INSTANCE_ID = cur_inst);       
     SELECT ERROR_MSG INTO error_txt FROM DBMS_RESUMABLE 
     WHERE SESSION_ID = cur_sid and INSTANCE_ID = cur_inst;
     -- Send email to receipient through UTL_SMTP package
     msg_body := 'Subject: Space Error Occurred Space limit reached for undo segment'||object_name ||'on'||
                         TO_CHAR(SYSDATE,' Month dd, YYYY, HH :MIam')||'. Error message was '||error_txt;
     mail_conn := UTL_SMTP.OPEN_CONNECTION('localhost', 25);
     UTL_SMTP.HELO(mail_conn, 'localhost');
     UTL_SMTP.MAIL(mail_conn, 'oracle@localhost');
     UTL_SMTP.RCPT(mail_conn, 'oracle@localhost');
     UTL_SMTP.DATA(mail_conn, msg_body);
     UTL_SMTP.QUIT(mail_conn);
     -- Abort the statement
     DBMS_RESUMABLE.ABORT(cur_sid);
  ELSE
     -- Set timeout to 8 hours
     DBMS_RESUMABLE.SET_TIMEOUT(28800);
  END IF;
     /* commit autonomous transaction */
     COMMIT;   
END;
/

 

 

分享到:
评论

相关推荐

    JESD--DDR4 Registering Clock Driver Spec PDF

    DDR4 Registering Clock Driver Spec PDF DDR4 Registering Clock Driver Spec PDF是JEDEC(Joint Electron Device Engineering Council,联合电子设备工程委员会)发布的一份规范文档,旨在规范DDR4记忆体的时钟...

    Registering_3DSC_ICP.rar

    总结来说,"Registering_3DSC_ICP.rar"文件包含了一个关于3D点云配准的完整工作流程,从环境配置到算法实现,再到数据处理和结果分析。这对于学习和研究点云处理,尤其是配准技术,提供了宝贵的实践资源。通过深入...

    JEDEC JESD82-31A:2019 DDR4 Registering Clock Driver Definition (

    DDR4 Registering Clock Driver Definition,即DDR4注册时钟驱动器定义,是JEDEC固态技术协会发布的标准文档JESD82-31A,主要用于规范DDR4内存系统中的时钟驱动器设计。这份2019年的更新版本详细阐述了DDR4RCD(DDR4...

    Remote COM registering远处COM注册

    Remote COM registering远处COM注册

    Registering_NDT_ICP.rar

    总的来说,"Registering_NDT_ICP.rar"提供的内容对于学习和实践点云配准技术非常有帮助,特别是对于那些希望掌握VS2015和PCL的开发者来说,这是一个宝贵的资源。通过理解NDT和ICP的工作原理,以及如何在实际项目中...

    Oracle JDBC 连接时的一个BUG

    标题中的“Oracle JDBC 连接时的一个BUG”指的是在使用Java数据库连接(JDBC)与Oracle数据库进行交互时出现的问题。Oracle JDBC驱动是Java应用程序连接到Oracle数据库的桥梁,但有时候由于各种原因,如代码错误、...

    image-registering.rar_图像配准

    在"image-registering.rar"这个压缩包中,包含了一个图像配准程序,专为初学者设计,让我们来深入探讨一下这个主题。 图像配准的目标是找到一个几何变换,将一张图像(源图像)转换到另一张图像(目标图像)的位置...

    Registering_FPFH_ICP.rar

    这个压缩包文件“Registering_FPFH_ICP.rar”包含了所有必要的代码和PCD(Point Cloud Data)点云文件,用于演示这一过程。 首先,我们来看VS2015与PCL 1.9.1的配置步骤。PCL是一个开源库,专注于处理三维点云数据...

    Thank you for registering Visual Studio 2010 Express for Windows Phone.

    Thank you for registering Visual Studio 2010 Express for Windows Phone.

    Registering and managing apps through

    优质资源,值得拥有

    Registering_PFH_ICP.rar

    在"Registering_PFH_ICP"项目中,你将找到包含的代码示例,它们演示了如何使用PCL实现PFH和ICP算法。同时,还提供了.pcd文件,这是一种常用的点云数据格式。你可以加载这些点云数据,应用上述配准方法,并计算配准...

    Optical Character Recognition 5.2 released

    After registering you get source code of component, free upgrades for a year and e-mail support. DISCLAIMER OF WARRANTY SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. AUTHOR DISCLAIMS ...

    as_extensions_flash_lite_digital_home

    Registering an ActionScript extension is crucial for making it available to Flash Lite applications. There are two primary methods for registration: 1. **Hard-Coded List**: In this approach, the ...

    Simple Book Registering System in Python Free Source Code.zip

    这是一个基于Python实现的简单图书管理系统源代码包。这个系统提供了基础的图书登记功能,适合初学者学习Python编程以及了解简单的数据库操作。以下是该系统涉及的关键知识点: 1. **Python编程语言**:Python是一...

    Kindle如何注册

    #### 一、准备工作 ... ... ... Sign in to get personalized recommendations....3. **填写邮箱地址**:在新页面中输入您的邮箱地址,并勾选“No, I am a new customer.”,然后点击“Sign in using our secure server”按钮...

    ActiveDocument

    If the application is executed without the "/embedding" switch, a dialog box will be displayed that has options for registering the server and creating a working file. When Register Server is selected...

    Amplify Shader Editor 1.4.3

    * Fixed Undo issue when undoing deleted property type nodes after saving shader * Fixed ‘Static Switch’ node registering duplicates in the material properties group * Improvements: * Cull, ...

    oracle jdbc补丁

    解决“Error while registering Oracle JDBC Diagnosability MBean.”把文件解压覆盖到目录$Oracle_Home\product\11.1.0\db_1\jdbc\lib 下,重新开启oracle sql developer就解决了。

Global site tag (gtag.js) - Google Analytics