oracle監控DDL語句
就是一個未做任何歸檔備份的9i資料庫老是被出現一個表被莫名drop,並在回收站不留任何痕跡,最後只得建立觸發器的方法,來跟蹤執行這個操作的時間和主機資訊,問題予以解決,記錄在此:
-- Create table
create table T_WCDMA_AUDIT_DDL
(
DDL_TIME VARCHAR2(30),
SESSION_ID NUMBER,
OS_USER VARCHAR2(200),
IP_ADDRESS VARCHAR2(200),
TERMINAL VARCHAR2(200),
HOST VARCHAR2(200),
USER_NAME VARCHAR2(30),
DDL_TYPE VARCHAR2(30),
OBJECT_TYPE VARCHAR2(18),
OWNER VARCHAR2(30),
OBJECT_NAME VARCHAR2(128),
SQL_TEXT VARCHAR2(4000)
);
--2.建立審計DDL觸發器
select to_char(sysdate,'yyyy-mm-dd hh:mm:ss') from dual;
create or replace trigger tri_WCDMA_ddl
after ddl on wcdma.schema
declare
sql_text ora_name_list_t;
i integer;
state_sql varchar2(4000);
begin
for i in 1..ora_sql_txt(sql_text) loop
state_sql := state_sql||sql_text(i);
end loop;
state_sql :=substrb(state_sql,1,4000);
insert into t_wcdma_audit_ddl
(ddl_time,
session_id,
os_user,
ip_address,
terminal,
host,
user_name,
ddl_type,
object_type,
owner,
object_name,
sql_text)
values
(to_char(sysdate,'yyyy-mm-dd hh:mm:ss'),
sys_context('USERENV','SESSIONID'),
sys_context('USERENV','OS_USER'),
sys_context('USERENV','IP_ADDRESS'),
sys_context('USERENV','TERMINAL'),
sys_context('USERENV','HOST'),
ora_login_user,
ora_sysevent,
ora_dict_obj_type,
ora_dict_obj_owner,
ora_dict_obj_name,
state_sql
);
exception when others then
null;
end;