包对象之Oracle如何编译失效包体


主题:如何Oracle编译失效的包体
作者:基毛飞上天

情况说明:在吗?可以帮忙重新编译一个包吗?我们这边编译不了!

处理思维:
(1)包头失效还是包体失效?
(2)是否存在阻碍的进程影响重新编译?
(3)如果存在阻碍,与应用人员沟通,是否可以尝试杀Process以及会话

1. 查看包头和包体是否失效?

从以下SQL语句输出得知,包头没有失效,包体失效了

目前创新互联已为近千家的企业提供了网站建设、域名、网络空间、网站托管、服务器托管、企业网站设计、红河网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

  • BEGIN pkg_test.ap_get_baTran(200,20180515); END;

  • 点击(此处)折叠或打开

    1. SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(to_char('7b4dpss4k3hc5'),NULL));

    2. PLAN_TABLE_OUTPUT
    3. --------------------------------------------------
    4. SQL_ID 7b4dpss4k3hc5, child number 0
    5. BEGIN pkg_test.ap_get_baTran(200,20180515); END;
    6. NOTE: cannot fetch plan for SQL_ID: 7b4dpss4k3hc5, CHILD_NUMBER: 0
    7.       Please verify value of SQL_ID and CHILD_NUMBER;
    8.       It could also be that the plan is no longer in cursor cache (check v$sql_plan)
  • 7. 杀会话

  • 经与应用人员沟通,可以尽情地杀会话,以及PROCESS(这个需要本地杀)
  • 点击(此处)折叠或打开

    1. alter system kill session '12481,8711';

  • 8. 再次查看是否有独占编译包体的锁

    检查出1719 ZJDB PKG_TEST Body Exclusive None,还是存在独占DDL锁的进程。按照以上的方式,杀1719的会话,是不对的!因为这个会话就是SYS用户正在执行重新编译的语句。不可能杀掉重新编译的语句嘛,所以看下还能从什么方面下手!

    点击(此处)折叠或打开

    1. SQL> select * from dba_ddl_locks where name='PKG_REPORT';

    2. SESSION_ID OWNER NAME TYPE MODE_HELD MODE_REQU
    3. ---------- --------------- ---------------- ------------------------- --------- ---------
    4.       9710 ZJDB PKG_TEST Table/Procedure/Type Null None
    5.        948 ZJDB PKG_TEST Table/Procedure/Type Null None
    6.      10155 ZJDB PKG_TEST Table/Procedure/Type Null None
    7.       6814 ZJDB PKG_TEST Table/Procedure/Type Null None
    8.       2851 ZJDB PKG_TEST Table/Procedure/Type Null None
    9.      21183 ZJDB PKG_TEST Table/Procedure/Type Null None
    10.      14698 ZJDB PKG_TEST Table/Procedure/Type Null None
    11.      16963 ZJDB PKG_TEST Table/Procedure/Type Null None
    12.      23503 ZJDB PKG_TEST Table/Procedure/Type Null None
    13.       2650 ZJDB PKG_TEST Table/Procedure/Type Null None
    14.      20671 ZJDB PKG_TEST Table/Procedure/Type Null None
    15.       1719 ZJDB PKG_TEST Body Exclusive None
    16.       9710 ZJDB PKG_TEST Body Null None
    17.      20671 ZJDB PKG_TEST Body Null None
    18.       6814 ZJDB PKG_TEST Body Null None
    19.      16963 ZJDB PKG_TEST Body Null None
    20.      21183 ZJDB PKG_TEST Body Null None
    21.        948 ZJDB PKG_TEST Body Null None
    22.       2851 ZJDB PKG_TEST Body Null None
    23.      10155 ZJDB PKG_TEST Body Null None
    24.      23503 ZJDB PKG_TEST Body Null None
    25.       2650 ZJDB PKG_TEST Body Null None
    26.      14698 ZJDB PKG_TEST Body Null None
    27. 23 rows selected.

    9. 找出ZJDB.PKG_TEST对应ddl锁的相关信息

    找出ZJDB.PKG_TEST对应的DDL锁的SID与会话SID符合的会话,机器名字和用户名字以及状态

    点击(此处)折叠或打开

    1. SQL> select b.saddr, b.sid, b.serial#,b.process,b.status,b.username, b.MACHINE from v$session b where b.sidin
    2.       ( Select b.sid From dba_ddl_locks a, v$session b Where a.session_id = b.SID and a.name = 'PKG_TEST' and owner='ZJDB')
    3.       order by b.username desc;

    4. SADDR SID SERIAL# PROCESS STATUS USERNAME MACHINE
    5. ---------------- ---------- ---------- ---------- -------- --------- ---------
    6. 070000A02BB0E7E0 1719 30765 37358470 ACTIVE SYS RACZJ-DB1
    7. 070000A010BFF958 10155 46885 33227250 ACTIVE ZJDB RACZJ-DB1
    8. 070000A00CB32110 9710 9641 27525876 ACTIVE ZJDB RACZJ-DB1
    9. 070000A023BC4438 2032 9479 31195338 ACTIVE ZJDB RACZJ-DB1
    10. 070000A0061E8210 23503 30787 55313168 ACTIVE ZJDB RACZJ-DB1
    11. 070000A0279C9920 948 44781 13631706 ACTIVE ZJDB RACZJ-DB1
    12. 070000A02B9B4FC0 893 27923 54263886 ACTIVE ZJDB RACZJ-DB1
    13. 070000A02BCA68C8 2650 48113 29033334 ACTIVE ZJDB RACZJ-DB1
    14. 070000A00DE3DE58 21183 59867 43516348 ACTIVE ZJDB RACZJ-DB1
    15. 070000A015A40440 18410 50345 3998656 ACTIVE ZJDB RACZJ-DB1
    16. 070000A009727FB0 16963 33555 66847560 ACTIVE ZJDB RACZJ-DB1
    17. 070000A023D20C00 2851 17117 10224286 ACTIVE ZJDB RACZJ-DB1
    18. 070000A02FB62590 1776 28699 46334786 ACTIVE ZJDB RACZJ-DB1
    19. 070000A015E08488 20671 38781 53150014 ACTIVE ZJDB RACZJ-DB1
    20. 070000A011386AF0 14698 60901 37421588 ACTIVE ZJDB RACZJ-DB1
    21. 070000A005CC69A8 20416 37977 30147116 ACTIVE ZJDB RACZJ-DB1
    22. 070000A001EE7AC0 21745 60937 8192734 ACTIVE ZJDB RACZJ-DB1
    23. 17 rows selected.
    10. 操作系统层面杀process

    --以sid=10155为例子,杀系统的process,这个杀process的操作,一般是在他们的主机杀process!

    点击(此处)折叠或打开

    1. SQL> select sid, SERIAL#,process,status from v$session where sid=10155;

    2.        SID SERIAL# PROCESS STATUS
    3. ---------- ---------- ------------------------ --------
    4.       10155 30765 37358425 ACTIVE
    5.       
    6. $ ps -ef|grep 37358425  
    7. $ kill -9 37358425                    --操作系统层面杀会话
    8. $ ps -ef|grep 37358452
    12. 数据库层面杀会话

    点击(此处)折叠或打开

    1. alter system kill session '10155,46885';
    2. alter system kill session '9710,9641';
    3. alter system kill session '2032,9479';
    4. alter system kill session '23503,30787';
    5. alter system kill session '948,44781';
    6. alter system kill session '893,27923';
    7. alter system kill session '2650,48113';
    8. alter system kill session '21183,59867';
    9. alter system kill session '18410,50345';
    10. alter system kill session '16963,33555';
    11. alter system kill session '2851,17117';
    12. alter system kill session '1776,28699';
    13. alter system kill session '20671,38781';
    14. alter system kill session '14698,60901';
    15. alter system kill session '20416,37977';
    16. alter system kill session '21745,60937';
    13. 查看创建包体的命令是否成功

    点击(此处)折叠或打开

    1. SQL> alter package ZJDB.PKG_TEST compile body;
    2. Package body altered.
    14. 相关链接

    http://www.itpub.net/forum.php?mod=viewthread&tid=1761963
    https://blog.csdn.net/u011146687/article/details/72808565









    文章名称:包对象之Oracle如何编译失效包体
    当前网址:http://pwwzsj.com/article/jichdg.html