Home > Database > Mysql Tutorial > Oracle使用系统级触发器审计重要帐号的DDL语句

Oracle使用系统级触发器审计重要帐号的DDL语句

WBOY
Release: 2016-06-07 17:21:57
Original
1245 people have browsed it

如果要审计数据库中的DDL操作,那么可以通过DDL触发器来实现,本节介绍一个例子,把数据库中的所有DDL操作都记录下来。本例子可以

如果要审计数据库中的DDL操作,那么可以通过DDL触发器来实现,本节介绍一个例子,把数据库中的所有DDL操作都记录下来。本例子可以在Oracle 8i或更高的版本中使用。

第一步,创建表空间和相关的日志表:

create tablespace statlog datafile '/oradata/statlog.dbf' size 200m;


create table stat$log_ddl

(

ddl_date date,

user_name varchar2(30),

ip_addr VARCHAR2(30),

obj_name VARCHAR2(50),

ddl_type VARCHAR2(30),

object_type VARCHAR2(18),

owner VARCHAR2(30),

SQL_TEXT VARCHAR2(1000)

) TABLESPACE STATLOG;

第二步,创建数据库级的DDL触发器,把所有的DDL操作都记录下来


CREATE OR REPLACE TRIGGER DDL_audit AFTER CREATE OR ALTER OR DROP OR TRUNCATE OR

GRANT OR REVOKE OR RENAME

on DATABASE

declare

ipaddr varchar2(20);

STEXT VARCHAR2(1000);

BEGIN

begin

select sys_context('USERENV', 'IP_ADDRESS') into ipaddr FROM dual;

exception when others then

ipaddr:='-';

end;

begin

select SQL_TEXT INTO STEXT FROM v$open_cursor WHERE UPPER(sql_text) LIKE 'ALTER%';

exception when others then

STEXT:='-';

end;

insert into sys.stat$log_DDL values

(sysdate,

user,

nvl (ipaddr,'-'),

NVL(ora_dict_obj_name,'-'),

NVL(ORA_SYSEVENT,'-'),

NVL(ora_dict_obj_type,'-'),

NVL(ora_dict_obj_owner,'-'),

STEXT

);

exception when others then

null;

end;

/

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template