设置数据库启动时自动keep对象

step1、创建表,保存需要keep的对象
   create table sys.pin_objects (owner varchar2(30), name varchar2(30));

step2、创建包,将需要keep的对象插入pin_objects表
create or replace procedure sys.sp_list_objs as
      pragma AUTONOMOUS_TRANSACTION;
      owner varchar2(30);
      name varchar2(30);
      cursor cr_objs is select owner, name
         from sys.v_$db_object_cache
         where type in ('PACKAGE','PROCEDURE') and (loads > 1 or kept='YES');
    begin
      delete from sys.pin_objects;
      commit;
      open cr_objs;
      loop
        fetch cr_objs into owner, name;
        exit when cr_objs%notfound;
        insert into sys.pin_objects values (owner, name);
        commit;
      end loop;
    end;

step3、创建包,将pin_objects中的对象keep到shared pool
CREATE OR REPLACE PROCEDURE sys.sp_keep_objs AS
      owner varchar2(30);
      name varchar2(30);
      cursor cr_objs is select owner ,name from sys.pin_objects;
    BEGIN
      open cr_objs;
      loop
        fetch cr_objs into owner, name;
        exit when cr_objs%notfound;
        sys.dbms_shared_pool.keep(owner || '.' || name);
      end loop;
      sys.dbms_shared_pool.keep('SYS.STANDARD');
      sys.dbms_shared_pool.keep('SYS.DIUTIL');
   END;
   
step4、创建触发器
CREATE OR REPLACE TRIGGER db_list_trig
      BEFORE SHUTDOWN ON DATABASE
    BEGIN
      sys.sp_list_objs;
    END;
    CREATE OR REPLACE TRIGGER db_keep_trig
      AFTER STARTUP ON DATABASE
    BEGIN
      sys.sp_keep_objs;
    END; 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27119051/viewspace-2124464/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27119051/viewspace-2124464/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值