主題
本文說明在數據庫啟動的時候
如何自動獲取Shared Pool裡最常用的過程和包等對象
正文
下面用實例來演示Startup之後和Shutdown之前
如何用Triger來完成自動管理的任務
創建一個供Triger調用的Procedure a.創建一個用來保存Procedure和Package的名稱的Table(list_tab)
SQL>create table sys
list_tab (owner varchar
(
)
NAME VARCHAR
(
));
Table created
b
創建一個Procedure(proc_pkgs_list)來保存Shared Pool裡面的對象名
SQL> create or replace PROCEDURE proc_pkgs_list AS
own varchar
(
);
nam varchar
(
);
cursor pkgs is
select owner
name
from SYS
v_$db_object_cache
where type in (
PACKAGE
PROCEDURE
)
and (loads >
or KEPT=
YES
);
BEGIN
delete from sys
list_tab;
commit;
open pkgs;
loop
fetch pkgs into own
nam;
exit when pkgs%notfound;
insert into sys
list_tab values (own
nam);
commit;
end loop;
end;
/
Procedure created
c
創建Procedure(proc_pkgs_keep)用來保存調用dbms_shared_pool包的結果(注
如果沒有dbms_shared_pool包
可以用dbmspool
sql腳本生成)
SQL> CREATE OR REPLACE PROCEDURE sys
proc_pkgs_keep AS
own varchar
(
);
nam varchar
(
);
cursor pkgs is
select owner
name
from sys
list_tab;
BEGIN
open pkgs;
loop
fetch pkgs into own
nam;
exit when pkgs%notfound;
SYS
dbms_shared_pool
keep(
|| own ||
|| nam ||
);
end loop;
sys
dbms_shared_pool
keep(
SYS
STANDARD
);
sys
dbms_shared_pool
keep(
SYS
DIUTIL
);
END;
/
Procedure created
.編譯測試Procedure SQL> execute sys
proc_pkgs_list;
PL/SQL procedure successfully completed
SQL> execute sys
proc_pkgs_keep;
PL/SQL procedure successfully completed
.創建Triger a. 在Instance shutdown之前的triger
SQL> CREATE OR REPLACE TRIGGER db_shutdown_list
BEFORE SHUTDOWN ON DATABASE
BEGIN
sys
proc_pkgs_list;
END;
/
Trigger created
b. 在Instance startup之後的triger
SQL> CREATE OR REPLACE TRIGGER db_startup_keep
AFTER STARTUP ON DATABASE
BEGIN
sys
proc_pkgs_keep;
END;
/
Trigger created
檢查alter
log文件
查看Triger是否成功
如果不成功
則在數據庫關閉或者啟動的時候會看到如下提示*** SHUTDOWN
Shutting down instance (immediate)
License high water mark =
Mon May
:
:
ALTER DATABASE CLOSE NORMAL
Mon May
:
:
SMON: disabling tx recovery
Mon May
:
:
Errors in file /
i/ora
/admin/hp
_
/udump/ora_
trc:
ORA
: trigger
DB_SHUTDOWN_LIST
is invalid and failed re
validation
SMON: disabling cache recovery
Mon May
:
:
Thread
closed at log sequence
Mon May
:
:
Completed: ALTER DATABASE CLOSE NORMAL
Mon May
:
:
ALTER DATABASE DISMOUNT
Completed: ALTER DATABASE DISMOUNT
*** STARTUP
Example
:
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION =
SMON: enabling tx recovery
Tue Apr
:
:
Errors in file /
i/ora
/admin/hp
_
/udump/ora_
trc:
ORA
: trigger
DB_STARTUP_KEEP
is invalid and failed re
valid
ation
Tue Apr
:
:
Completed: alter database open
Tue Apr
:
:
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION =
Example
:
SMON: enabling tx recovery
Tue Apr
:
:
Errors in file /
i/ora
/admin/hp
_
/udump/ora_
trc:
ORA
: error occurred at recursive SQL level
ORA
: missing identifier
ORA
: at
SYS
DBMS_UTILITY
line
ORA
: at
SYS
DBMS_SHARED_POOL
line
ORA
: at
SYS
DBMS_SHARED_POOL
line
ORA
: at
SYS
PROC_PKGS_KEEP
line
ORA
: at line
Tue Apr
:
:
Completed: alter database open
In the /
i/ora
/admin/hp
_
/udump/ora_
trc file:
Error in executing triggers on STARTUP
***
ksedmp: internal or fatal error
ORA
: error occurred at recursive SQL level
ORA
: missing identifier
ORA
: at
SYS
DBMS_UTILITY
line
ORA
: at
SYS
DBMS_SHARED_POOL
line
ORA
: at
SYS
DBMS_SHARED_POOL
line
ORA
: at
SYS
PROC_PKGS_KEEP
line
ORA
: at line
以上Procedure和Triger必須在sys的模式下執行
並且保證表list_tab的存在
From:http://tw.wingwit.com/Article/program/Oracle/201311/17326.html