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

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

Jun 07, 2016 pm 05:21 PM

如果要审计数据库中的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

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Reduce the use of MySQL memory in Docker Reduce the use of MySQL memory in Docker Mar 04, 2025 pm 03:52 PM

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library How to solve the problem of mysql cannot open shared library Mar 04, 2025 pm 04:01 PM

How to solve the problem of mysql cannot open shared library

What is SQLite? Comprehensive overview What is SQLite? Comprehensive overview Mar 04, 2025 pm 03:55 PM

What is SQLite? Comprehensive overview

Run MySQl in Linux (with/without podman container with phpmyadmin) Run MySQl in Linux (with/without podman container with phpmyadmin) Mar 04, 2025 pm 03:54 PM

Run MySQl in Linux (with/without podman container with phpmyadmin)

Running multiple MySQL versions on MacOS: A step-by-step guide Running multiple MySQL versions on MacOS: A step-by-step guide Mar 04, 2025 pm 03:49 PM

Running multiple MySQL versions on MacOS: A step-by-step guide

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

How do I configure SSL/TLS encryption for MySQL connections?

See all articles