Oracle ORA-06512&ORA-08103 object no longer exists, the index on the table is deleted during the query

    Recently, I encountered a very strange problem. Two stored procedures of an Oracle database, it will not be a problem to run separately, but run one of the stored procedures

You will encounter an ORA08103 error.

    1. The error message of the problem is as follows:

Error ORA-08103: object no longer exists, ORA-06512: in "REPD.ETL_PPACKAGE", line 7901

--According to the error message, the SQL statement involved in the error report is an Insert into ...... select

 V_SQL2:= ' INSERT INTO DATA_T (
         C1   ,
         C2  ,
        C3
          )
        SELECT
          b.T1,
          b.T2,
          b.T3,
          FROM data_b;

    2. Problem analysis

    1. The first impression may be cross-user data access, the table was deleted by the host or the truncate operation occurred on the error table. Therefore, use ddl audit monitoring data

DDL operations that occurred in the library.

--首先sys确认触发器相关的参数
show parameter _system_trig_enabled

--如果_system_trig_enabled参数值为false,修改为true
alter system set "_system_trig_enabled"=true; 

--确认触发器相关的参数_system_trig_enabled参数值为true
show parameter _system_trig_enabled

--SYS登陆数据库创建审计表
-- Create table
create table AUDIT_DDL_OBJ
(
  opr_time    DATE,
  session_id  NUMBER,
  os_user     VARCHAR2(200),
  ip_address  VARCHAR2(200),
  terminal    VARCHAR2(200),
  host        VARCHAR2(200),
  user_name   VARCHAR2(30),
  ddl_type    VARCHAR2(30),
  ddl_sql     CLOB,
  object_type VARCHAR2(18),
  owner       VARCHAR2(30),
  object_name VARCHAR2(128)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
--创建DDL审计触发器
CREATE OR REPLACE TRIGGER DDL_Audit_Trigger
AFTER drop or alter or truncate ON DATABASE
/*
||名称:DDL事件审计触发器
||说明:
*/
DECLARE
   Session_Id_Var   NUMBER;          /* 会话ID */
   Os_User_Var      VARCHAR2(200);   /* 终端OS用户 */
   IP_Address_Var   VARCHAR2(200);   /* 终端IP */
   Terminal_Var     VARCHAR2(200);   /* 终端 */
   Host_Var         VARCHAR2(200);   /* 终端主机名 */
   Cut              NUMBER;          /* SQL列表长度 */
   Sql_Text         ORA_NAME_LIST_T; /* SQL_TEXT 列表 */
   L_Trace          NUMBER;          /* 循环执行条件 */
   DDL_Sql_Var      VARCHAR2(2000);  /* DDL语句 */
   stmt     clob := NULL;
   n        NUMBER;
BEGIN
   /* 获取操作用户信息 */
   SELECT   SYS_CONTEXT('USERENV','SESSIONID'),
            SYS_CONTEXT('USERENV','OS_USER'),
            SYS_CONTEXT('USERENV','IP_ADDRESS'),
            SYS_CONTEXT('USERENV','TERMINAL'),
            SYS_CONTEXT('USERENV','HOST')
   INTO     Session_Id_Var,
            Os_User_Var,
            IP_Address_Var,
            Terminal_Var,
            Host_Var
   FROM     DUAL;
   /* 获取DDL SQL语句 */
   /*BEGIN
    SELECT sql_text
      INTO DDL_Sql_Var
      FROM sys.v_$sql a, sys.v_$session b
     WHERE a.hash_value = b.sql_hash_value
       AND b.status = 'active'
       AND b.audsid = SYS_CONTEXT('userenv', 'sessionid');
   EXCEPTION
      WHEN OTHERS THEN
         NULL;
   END;*/
   n := ora_sql_txt(sql_text);
   FOR i IN 1 .. n LOOP
    stmt := stmt || sql_text(i);
   END LOOP;
   /* 记录登陆审计信息 */
   INSERT INTO Audit_DDL_OBJ(
               Opr_Time,     /* 操作时间 */
               Session_Id,   /* 会话ID */
               OS_User,      /* 终端OS用户 */
               IP_Address,   /* 终端IP地址 */
               Terminal,     /* 终端 */
               Host,         /* 终端主机名 */
               User_Name,    /* ORACLE 用户名*/
               DDL_Type,     /* DDL操作类型 */
               DDL_Sql,      /* DDL语句 */
               Object_Type,  /* 操作对象类型 */
               Owner,        /* 对象拥有者 */
               Object_Name   /* 对象名称 */
              )
       VALUES( SYSDATE,
               Session_Id_Var,
               Os_User_Var,
               IP_Address_Var,
               Terminal_Var,
               Host_Var,
               ORA_LOGIN_USER,
               ORA_SYSEVENT,
               stmt,
               ORA_DICT_OBJ_TYPE,
               ORA_DICT_OBJ_OWNER,
               ORA_DICT_OBJ_NAME);
   COMMIT;
EXCEPTION
   WHEN OTHERS THEN
      NULL;
END DDL_Audit_Trigger;
========
触发器后期清理
drop triger DDL_Audit_Trigger;

drop table AUDIT_DDL_OBJ;

alter system set "_system_trig_enabled"=false;

    2. Analyze the error

    According to the information of the DDL audit table AUDIT_DDL_OBJ, no DROP and TRUNCATE operations related to DATA_T were found.

    ​3. After communicating with the person in charge of the system, use 10046 to track the conversations that execute the batch and report errors

1 查询要跟踪的用户会话信息
select sid,serial#,username from v$session where username='REPD';
2 开启10046跟踪
exec dbms_system.set_ev(sid,serial#,10046,12,'');
3 程序抛出错误后结束10046跟踪
exec dbms_system.set_ev(sid,serial#,10046,0,'');
4 获取10046跟踪日志文件,第1步中查询到的sid号
 select p.tracefile from V$PROCESS p,v$session s where s.paddr=p.addr and sid=&sid;

    ​4. Obtain the data file number and data block number of the ORA08103 error object according to the 10046 trace file

    ​5. According to the data file number and data block number prompted by the 10046 tracking file ORA08103, determine an index object to insert into .... select related tables

    ​6, review the DDL audit trigger again, before the stored procedure runs the batch, there is indeed a drop operation of the index

    ​7. So far, the root cause of the ORA08103 problem is located

    ​The reason for the ORA08103 error is that one of the stored procedures is performing the insert into ..... select operation, and the other stored procedure is for insert 

The index on the table of the select part of into ... select executes a drop, which causes the select query to report an exception error ORA08103 and exit.

    ​8. Troubleshoot two stored procedures that execute error reports at the same time. One of the stored procedures does drop the index monitored by the audit table.

Three, problem solving

    ​After communicating with the customer, shielding the operation of the drop index in the stored procedure, and then executing the stored procedure, there is no more ORA08103 error.

 

Four, supplement

    The possible reasons for the ORA08103 error report are:

    ​1. The operated object was indeed deleted by other users

    ​2. The operated object has been truncate operation

    ​3, the object dictionary information caused by the damage of the system table space data block is inconsistent with the data object information of the table space where the table is located

    4. The operated object has DDL such as adding field operation

    5. The index on the operated object is deleted, and the operation uses the index on the object

 

 

 

Guess you like

Origin blog.csdn.net/www_xue_xi/article/details/104737585