暂无图片
Troubleshooting dbms_sqltune ORA-04068 ORA-04065 ORA-06508 ORA-06512 在做异常恢复后
最近更新:2022-03-11 14:21:05

前几日有个库sysaux和部分业务表空间数据文件损坏,在数据库强制异常恢复后, 提示dbms_sqltune使用sql profile无法使用,这个问题与对象的先后创建顺序或部分重建导致,错误信息如下,这里我还原一下问题和分享一下思路。

ORA-04068: existing state of packages has been discarded
ORA-04065: not executed, altered or dropped stored procedure "SYS.DBMS_SQLTUNE_INTERNAL"
ORA-06508: PL/SQL: could not find program unit being called: "SYS.DBMS_SQLTUNE_INTERNAL"
ORA-06512: at "SYS.DBMS_SQLTUNE", line 6759
ORA-06512: at "SYS.DBMS_SQLTUNE", line 6729
ORA-06512: at line 6

1, 还原问题

SQL> @o dbms_sqltune

owner                     object_name                    object_type          status           OID      D_OID CREATED             LAST_DDL_TIME
------------------------- ------------------------------ -------------------- --------- ---------- ---------- ------------------- -------------------
SYS                       DBMS_SQLTUNE                   PACKAGE              VALID          13804            2019-04-17 01:03:55 2020-03-20 05:50:42
SYS                       DBMS_SQLTUNE                   PACKAGE BODY         VALID          19191            2019-04-17 01:11:27 2019-04-17 01:11:27
SYS                       DBMS_SQLTUNE_INTERNAL          PACKAGE              VALID          17064            2019-04-17 01:07:16 2019-04-17 01:07:16
SYS                       DBMS_SQLTUNE_INTERNAL          PACKAGE BODY         VALID          19188            2019-04-17 01:11:25 2019-04-17 01:11:25

字典部分字段说明
obj$
  ctime         date not null,                       /* object creation time */
  mtime         date not null,                      /* DDL modification time */
  stime         date not null,          /* specification timestamp (version) */
  status        number not null,            /* status of object (see KQD.H): */

dependency$                                 /* dependency table */
d_obj#        number not null,                  /* dependent object number */
  d_timestamp   date not null,   /* dependent object specification timestamp */
  order#        number not null,                             /* order number */
  p_obj#        number not null,                     /* parent object number */
  p_timestamp   date not null,      /* parent object specification timestamp */
  d_owner#      number,                           /*  dependent owner number */
  property      number not null,                   /* 0x01 = HARD dependency */
                                                   /* 0x02 = REF  dependency */
                                          /* 0x04 = FINER GRAINED dependency */
  d_attrs       raw("M_CSIZ"), /* Finer grain attr. numbers if finer grained */
  d_reason      raw("M_CSIZ"))  /* Reason mask of attrs causing invalidation */

SQL>          SELECT
              do.obj# d_obj,
              do.name d_name,
              do.type# d_type,
              po.obj# p_obj,
              po.name p_name,
              to_char(p_timestamp,'DD-MON-YYYY HH24:MI:SS') "P_Timestamp",
              to_char(po.stime ,'DD-MON-YYYY HH24:MI:SS') "STIME", po.ctime,po.mtime,
              decode(sign(po.stime-p_timestamp),0,'SAME','*DIFFER*') X
         FROM sys.obj$ do, sys.dependency$ d, sys.obj$ po
         WHERE P_OBJ#=po.obj#(+)
         AND D_OBJ#=do.obj#
                 and p_obj# in(select obj#  from obj$ where name like 'DBMS_SQLTUNE_INTERNAL%'  and type# in(9,11) )
         AND do.status=1 /*dependent is valid*/
         AND po.status=1 /*parent is valid*/
         --AND po.stime!=p_timestamp /*parent timestamp not match*/
         ORDER BY 2,1;
  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17
......