Oracle System Event Triggers
General | |||||
Data Dictionary Objects |
|
||||
Related System Privileges |
administer database trigger alter any trigger create trigger create any trigger drop any trigger |
||||
System Event Trigger Types |
AFTER STARTUP BEFORE SHUTDOWN AFTER LOGON BEFORE LOGOFF AFTER DB_ROLE_CHANGE -- for Data Guard failover and switchover AFTER SUSPEND AFTER SERVERERROR (does not trap ...
|
||||
Database Level Event Triggers | SELECT a.obj#,
a.sys_evts, b.name FROM trigger$ a,obj$ b WHERE a.sys_evts > 0 AND a.obj#=b.obj# AND baseobject = 0; |
||||
Schema Level Event Triggers | SELECT a.obj#,
a.sys_evts, b.name FROM trigger$ a,obj$ b WHERE a.sys_evts > 0 AND a.obj#=b.obj# AND baseobject = 88; |
||||
Disabling System Triggers |
If there is an error in a system trigger, for example an AFTER STARTUP trigger, it may be impossible to start the database. The following is the method for disabling system triggers. | ||||
/ as sysdba set linesize 150 col NAME format a30 col VALUE format a20 col DESCRIPTION format a60 SELECT x.ksppinm NAME, y.ksppstvl VALUE, ksppdesc DESCRIPTION FROM x$ksppi x, x$ksppcv y WHERE x.inst_id = userenv('Instance') AND y.inst_id = userenv('Instance') AND x.indx = y.indx AND x.ksppinm = '_system_trig_enabled'; ALTER SYSTEM SET "_system_trig_enabled" = TRUE SCOPE=BOTH; |
|||||
Create SYSTEM EVENT TRIGGER | |||||
System Trigger Demo Demo table and the logproc procedure (below) must be built before the trigger will compile |
CREATE OR REPLACE TRIGGER CALL / |
||||
CREATE TABLE
connection_audit ( login_date DATE, user_name VARCHAR2(30)); CREATE OR REPLACE PROCEDURE logproc IS BEGIN INSERT INTO connection_audit (login_date, user_name) VALUES (SYSDATE, USER); END logproc; / CREATE OR REPLACE TRIGGER logintrig AFTER LOGON ON DATABASE CALL logproc / conn sh/sh conn scott/tiger conn uwclass/uwclass SELECT * FROM connection_audit; drop trigger logintrig; |
|||||
Demo Application To Log Logon Attempts ... Both Successful And Failed |
CREATE OR REPLACE TRIGGER END / |
||||
truncate table connection_audit; -- trigger to trap successful logons CREATE OR REPLACE TRIGGER logon_audit AFTER LOGON ON DATABASE BEGIN INSERT INTO connection_audit (login_date, user_name) VALUES (SYSDATE, USER); END logon_audit; / conn scott/tiger conn sh/sh conn / as sysdba conn uwclass/uwclass SELECT * FROM connection_audit; -- trigger to trap unsuccessful logons CREATE OR REPLACE TRIGGER logon_failures AFTER SERVERERROR ON DATABASE BEGIN IF (IS_SERVERERROR(1017)) THEN INSERT INTO connection_audit (login_date, user_name) VALUES (SYSDATE, 'ORA-1017'); END IF; END logon_failures; / conn scott/tigre conn abc/def conn test/test conn uwclass/uwclass SELECT * FROM connection_audit; /* other errors that could be trapped include: ORA-01004 - default username feature not supported ORA-01005 - null password given ORA-01035 - Oracle only available to users with restricted session priv ORA-01045 - create session privilege not granted */ |
|||||
Demo To Log System Errors |
CREATE TABLE servererror_log ( error_datetime TIMESTAMP, error_user VARCHAR2(30), db_name VARCHAR2(9), error_stack VARCHAR2(2000), captured_sql VARCHAR2(1000)); CREATE OR REPLACE TRIGGER log_server_errors AFTER SERVERERROR ON DATABASE DECLARE captured_sql VARCHAR2(1000); BEGIN SELECT q.sql_text INTO captured_sql FROM gv$sql q, gv$sql_cursor c, gv$session s WHERE s.audsid = audsid AND s.prev_sql_addr = q.address AND q.address = c.parent_handle; INSERT INTO servererror_log (error_datetime, error_user, db_name, error_stack, captured_sql) VALUES (systimestamp, sys.login_user, sys.database_name, dbms_utility.format_error_stack, captured_sql); END log_server_errors; / |
||||
After Logon Trigger for Tracing |
CREATE OR REPLACE
TRIGGER trace_trig AFTER LOGON ON DATABASE DECLARE sqlstr VARCHAR2(200) := 'ALTER SESSION SET EVENTS ''10046 TRACE NAME CONTEXT FOREVER, LEVEL 4'''; BEGIN IF (USER = 'UWCLASS') THEN execute immediate sqlstr; END IF; END trace_trig; / |
||||
After Logon Trigger for Outlines |
CREATE OR REPLACE
TRIGGER trace_trig AFTER LOGON ON DATABASE DECLARE sqlstr VARCHAR2(200) := 'alter session set use_stored_outlines = uw_outlines'; BEGIN IF (USER = 'UWCLASS') THEN execute immediate sqlstr; END IF; END trace_trig; / |
||||
Drop SYSTEM EVENT TRIGGER | |||||
Drop Trigger | DROP TRIGGER |
||||
DROP TRIGGER logon_failures; |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9907339/viewspace-1047085/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Database Triggers and event attributes--Database System EventsDatabase
- Database Triggers and event attributes--Database System Events【Blog 搬家】Database
- Database Triggers and event attributes--Event AttributesDatabase
- Database Triggers and event attributes--Event Attributes【Blog 搬家】Database
- Database Triggers and event attributes--IntroductionDatabase
- Database Triggers and event attributes--DDL/Client EventsDatabaseclient
- v$system_event解析
- alter system events與alter system event的區別
- Database Triggers and event attributes--Introduction[Blog 搬家]Database
- (轉):學習Oracle動態效能表-(20)-V$SYSTEM_EVENTOracle
- Oracle 21C TriggersOracle
- Database Triggers and event attributes--DDL/Client Events【Blog 搬家】Databaseclient
- 使用 WebSphere Adapter 整合 Oracle Workflow Business Event System 實現業務整合WebAPTOracle
- v session_wait v session_event v system_eventSessionAI
- v$session_event , v$system_event , v$session_waitSessionAI
- V$SYSTEM_EVENT等使用詳解
- Oracle動態效能檢視學習筆記(9)_v$system_eventOracle筆記
- alter system set event和set events的區別
- 學習動態效能表(18)--V$SYSTEM_EVENT
- Alter system in OracleOracle
- 幾個重要檢視(V$SYSTEM_EVENT V$SESSION_EVENT V$SESSION_WAIT)SessionAI
- oracle event 2 (zt)Oracle
- 【Oracle】Oracle常用EVENT之三Oracle
- 【Oracle】Oracle常用EVENT之二Oracle
- 【Oracle】Oracle常用EVENT之一Oracle
- Oracle之Triggers管理_20091229Oracle
- Oracle SYSTEM_PLANOracle
- ORACLE EVENT && ORADEBUGOracle
- ORACLE event和說明Oracle
- ORACLE 配置event引數Oracle
- oracle event 10513作用Oracle
- 設定 oracle event traceOracle
- Oracle常用Event參考Oracle
- Triggers 授權
- 使用 oracle 10046 eventOracle
- oracle wait event 等待事件OracleAI事件
- Oracle V$event_name 整理Oracle
- Oracle EVENT用法參考列表Oracle