审计(Audit) 用于监视用户所执行的数据库操作,审计记录可存在数据字典表(称为审计记录:存储在system表空间中的 SYS.AUD$ 表中,可通过视图dba_audit_trail查看)或操作系统审计记录中(默认位置为$ORACLE_BASE/admin/$ORACLE_SID/adump/).。默认情况下审计是没有开启的。

不管你是否打开数据库的审计功能,以下这些操作系统会强制记录:用管理员权限连接Instance;启动数据库;关闭数据库。

和审计相关的两个主要参数1、audit_sys_operationsAUDIT_SYS_OPERATIONS enables or disables the auditing of top-level operations, which are SQL statements directly issued by users when connecting with SYSDBA or SYSOPER privileges.(SQL statements run from within PL/SQL procedures or functions are not considered top-level.) The audit records are written to the operating system'saudit trail. The audit records will be written in XML format if the AUDIT_TRAIL initialization parameter is set to xml or xml, extended.

On UNIX platforms, if the AUDIT_SYSLOG_LEVEL parameter has also been set, then it overrides the AUDIT_TRAIL parameter and SYS audit records are written to the system audit log using the SYSLOG utility.

默认为false,当设置为true时,所有sys用户(包括以sysdba, sysoper身份登录的用户)的操作都会被记录,audit trail不会写在aud$表中,这个很好理解,如果数据库还未启动aud$不可用,那么像conn /as sysdba这样的连接信息,只能记录在其它地方。如果是windows平台,audti trail会记录在windows的事件管理中,如果是linux/unix平台则会记录在audit_file_dest参数指定的文件中。2、audit_trailAUDIT_TRAIL = { none | os | db | db,extended | xml | xml,extended }

none or false - Auditing is disabled. 是默认值,不做审计;

db or true - Auditing is enabled, with all audit records stored in the database audit trial (SYS.AUD$). 将audit trail 记录在数据库的审计相关表中,如aud$,审计的结果只有连接信息;

db,extended - As db, but the SQL_BIND and SQL_TEXT columns are also populated. 审计结果里面除了连接信息还包含了当时执行的具体语句;

xml- Auditing is enabled, with all audit records stored as XML format OS files. 10g里新增的。

xml,extended - As xml, but the SQL_BIND and SQL_TEXT columns are also populated. 10g里新增的。

os- Auditing is enabled, with all audit records directed to the operating system's audit trail. 将audit trail 记录在操作系统文件中,文件名由audit_file_dest参数指定;

注:这两个参数是static参数,需要重新启动数据库才能生效。

当开启审计功能后,可在三个级别对数据库进行审计:Statement(语句)、Privilege(权限)、object(对象)。

1、 Statement(语句审计)

对某种类型的SQL语句审计,不指定结构或对象。比如audit table 会审计数据库中所有的create table、drop table、truncate table语句,alter session by cmy会审计cmy用户所有的数据库连接。

2、 Privilege(权限审计)

当用户使用了该权限则被审计,如执行grant select any table to a,当执行了audit select any table语句后,当用户a 访问了用户b的表时(如select * from b.t)会用到select any table权限,故会被审计。

注意:用户是自己表的所有者,所以用户访问自己的表不会被审计。

3 、 Object(对象审计)

对一特殊模式对象上的指定语句的审计。 如审计on关键字指定对象的相关操作,如aduit alter, delete, drop, insert on cmy.t by scott; 这里会对cmy用户的t表进行审计,但同时使用了by子句,所以只会对scott用户发起的操作进行审计。

注意:Oracle没有提供对schema中所有对象的审计功能,只能一个一个对象审计,对于后面创建的对象,Oracle则提供on default子句来实现自动审计,比如执行audit drop on default by access;后,对于随后创建的对象的drop操作都会审计。但这个default会对之后创建的所有数据库对象有效,似乎没办法指定只对某个用户创建的对象有效,相比 trigger 可以对schema的DDL进行“审计”,这个功能稍显不足。

审计的一些其他选项:

1、by access / by session

by access  每一个被审计的操作都会生成一条audit trail。

by session 一个会话里面同类型的操作只会生成一条audit trail,默认为by session。

2、whenever [not] successful

whenever successful 操作成功(dba_audit_trail中returncode字段为0) 才审计,

whenever not successful 反之。省略该子句的话,不管操作成功与否都会审计。

和审计相关的视图

1、dba_audit_trail

保存所有的audit trail,实际上它只是一个基于aud$的视图。其它的视图dba_audit_session,dba_audit_object,dba_audit_statement都只是dba_audit_trail的一个子集。

2、dba_stmt_audit_opts

可以用来查看statement审计级别的audit options,即数据库设置过哪些statement级别的审计。dba_obj_audit_opts,dba_priv_audit_opts视图功能与之类似。

3、all_def_audit_opts

用来查看数据库用on default子句设置了哪些默认对象审计。

取消审计

将对应审计语句的 audit 改为noaudit即可。如audit session whenever successful;取消审计noaudit session whenever successful;

试验如下:

首先,检查审计功能是否开启。SQL> SHOW PARAMETER AUDIT

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

audit_file_dest string C:\ORACLE\PRODUCT\10.2.0\ADMIN

\DB10G\ADUMP

audit_sys_operations boolean FALSE

audit_trail string NONE

SQL>审计相关的表安装SQL> connect / AS SYSDBA

SQL> select * from sys.aud$;     --没有记录返回

SQL> select * from dba_audit_trail;   - 没有记录返回

如果做上述查询的时候发现表不存在,说明审计相关的表还没有安装,需要安装。

SQL> connect / as sysdba

SQL> @$ORACLE_HOME/rdbms/admin/cataudit.sql

审计表安装在SYSTEM表空间。所以要确保SYSTEM表空间又足够的空间存放审计信息。

安装后要重启数据库基于Oracle的稳定性及性能考虑,可以将审计相关的表移动到其他表空间。connect / as sysdba;

alter table aud$ move tablespace ;

alter index I_aud1 rebuild online tablespace ;

alter table audit$ move tablespace;

alter index i_audit rebuild online tablespace ;

alter table audit_actions move tablespace ;

alter index i_audit_actions rebuild online tablespace ;开启审计功能。SQL> alter system set audit_sys_operations=TRUE scope=spfile;

--审计管理用户(以sysdba/sysoper角色登陆)

SQL> alter system set audit_trail=db,extended scope=spfile;

SQL> startup force;

SQL> show parameter auditNAME TYPE VALUE

------------------------------------ ----------- ------------------------------

audit_file_dest string C:\ORACLE\PRODUCT\10.2.0\ADMIN

\DB10G\ADUMP

audit_sys_operations boolean TRUE

audit_trail string DB, EXTENDED

SQL>1、对创建表的审计会话1中(已sysdba登录)SQL> audit create table by user1;审计已成功。会话2中(已user1用户登录)SQL> create table test (id number);Table createdSQL> create table test (id number);create table test (id number)ORA-00955: 名称已由现有对象使用SQL> select username,returncode,action_name from dba_audit_trail;USERNAME                       RETURNCODE ACTION_NAME

------------------------------ ---------- ----------------------------

USER1                                     0 CREATE TABLE

USER1                                   955 CREATE TABLESQL>2、对修改、删除表的审计由于没有对drop table进行单独审计的操作,需要添加audit table by user(此命令将对create table ,drop table, truncate table 进行审计)会话1中:SQL> audit table by user1;审计已成功。会话2中:SQL> create table test(id number);Table createdSQL> alter table test add name varchar2(100);Table alteredSQL> drop table test;Table droppedSQL> select username,returncode,action_name from dba_audit_trail;USERNAME                       RETURNCODE ACTION_NAME

------------------------------ ---------- ----------------------------

USER1                                     0 CREATE TABLE

USER1                                     0 ALTER TABLE

USER1                                     0 DROP TABLE3、对视图的审计对创建视图(create view)进行审计会话1中:SQL> audit create view by USER1;审计已成功。会话2中:SQL> create view test0 as select * from test;SQL> create view test0 as select * from test;名称已由现有对象使用

SQL>select username,returncode,action_name from dba_audit_trail;

USERNAME                       RETURNCODE ACTION_NAME

------------------------------ ---------- ----------------------------USER1 0 CREATE VIEW

USER1                                 955 CREATE VIEW会话1中:SQL> audit view by USER1;审计已成功。会话2中:

SQL> drop view test0;View droppedSQL> drop view test0;drop view test0ORA-00942: 表或视图不存在SQL> select username,returncode,action_name from dba_audit_trail;USERNAME                       RETURNCODE ACTION_NAME

------------------------------ ---------- ----------------------------

USER1                                     0 DROP VIEW

USER1                                   942 DROP VIEW4、对程序包的审计

会话1中:

SQL> audit procedure by user1;审计已成功。

SQL> truncate table aud$;

表被截断。

会话2中:

SQL> create procedure test1 as

2  begin

3  null;

4  end;

5  /

Procedure created

SQL> drop procedure test1;

Procedure dropped

SQL> drop procedure test1;

drop procedure test1

ORA-04043: 对象 TEST1 不存在

SQL> select username,returncode,action_name from dba_audit_trail;

USERNAME                       RETURNCODE ACTION_NAME

------------------------------ ---------- ----------------------------

USER1                                     0 CREATE PROCEDURE

USER1                                     0 DROP PROCEDURE

USER1                                  4043 DROP PROCEDURE5、对用户的审计audit user by user综上所述:

1. 对表的审计:可以单独对表的create,alter进行审计,如果要对drop操作进行审计需要对表加audit table(该命令包含有create table,drop table,truncate table).

2. 对视图的审计:可以单独对视图的create进行审计,如果要对drop操作进行审计需要对视图加audit view(该命令包含有create view,drop view).

3. 对程序包的审计:可以对包(函数,存储过程等)的create进行审计,如果需要对drop操作进行审计需要加audit procedure(该命令对CREATE FUNCTION, CREATE LIBRARY , CREATE PACKAGE, CREATE PACKAGE BODY, CREATE PROCEDURE, DROP FUNCTION, DROP LIBRARY, DROP PACKAGE, DROP PROCEDURE进行审计)

4. 对用户的审计:可以通过audit user(该命令包含 create user,alter user,drop user)进行审计以下是对上面内容的一个补充。

Maintenance and SecurityAuditing should be planned carefully to control the quantity of audit information. Only audit specific operations or objects of interest. Over time you can refine the level of auditing to match your requirements.

The database audit trail must be deleted, or archived, on a regular basis to prevent the SYS.AUD$ table growing to an unnacceptable size.Only DBAs should have maintenance access to the audit trail. Auditing modifications of the data in the audit trail itself can be achieved using the following statement:AUDIT INSERT, UPDATE, DELETE ON sys.aud$ BY ACCESS;The OS and XML audit trails are managed through the OS. These files should be secured at the OS level by assigning the correct file permissions.

Fine Grained Auditing (FGA)Fine grained auditing extends Oracle standard auditing capabilities by allowing the user to audit actions based on user-defined predicates. It is independant of the AUDIT_TRAIL parameter setting and all audit records are stored in the FGA_LOG$ table, rather than the AUD$ table. The following example illustrates how fine grained auditing is used.

First, create a test table.CONN audit_test/password

CREATE TABLE emp (

empno NUMBER(4) NOT NULL,

ename VARCHAR2(10),

job VARCHAR2(9),

mgr NUMBER(4),

hiredate DATE,

sal NUMBER(7,2),

comm NUMBER(7,2),

deptno NUMBER(2)

);

INSERT INTO emp (empno, ename, sal) VALUES (9999, 'Tim', 1);

INSERT INTO emp (empno, ename, sal) VALUES (9999, 'Larry', 50001);

COMMIT;The following policy audits any queries of salaries greater than £50,000.CONN sys/password AS sysdba

BEGIN

DBMS_FGA.add_policy(

object_schema => 'AUDIT_TEST',

object_name => 'EMP',

policy_name => 'SALARY_CHK_AUDIT',

audit_condition => 'SAL > 50000',

audit_column => 'SAL');

END;

/Querying both employees proves the auditing policy works as expected.CONN audit_test/password

SELECT sal FROM emp WHERE ename = 'Tim';

SELECT sal FROM emp WHERE ename = 'Larry';

CONN sys/password AS SYSDBA

SELECT sql_text

FROM dba_fga_audit_trail;

SQL_TEXT

------------------------------------------

SELECT sal FROM emp WHERE ename = 'Larry'

1 row selected.

SQL>Extra processing can be associated with an FGA event by defining a database procedure and associating this to the audit event. The following example assumes the FIRE_CLERK procedure has been defined:BEGIN

DBMS_FGA.add_policy(

object_schema => 'AUDIT_TEST',

object_name => 'EMP',

policy_name => 'SALARY_CHK_AUDIT',

audit_condition => 'SAL > 50000',

audit_column => 'SAL',

handler_schema => 'AUDIT_TEST',

handler_module => 'FIRE_CLERK',

enable => TRUE);

END;

/The DBMS_FGA package contains the following procedures:

ADD_POLICY

DROP_POLICY

ENABLE_POLICY

DISABLE_POLICYIn Oracle9i fine grained auditing was limited queries, but in Oracle 10g it has been extended to include DML statements, as shown by the following example.-- Clear down the audit trail.

CONN sys/password AS SYSDBA

TRUNCATE TABLE fga_log$;

SELECT sql_text FROM dba_fga_audit_trail;

no rows selected.

-- Apply the policy to the SAL column of the EMP table.

BEGIN

DBMS_FGA.add_policy(

object_schema => 'AUDIT_TEST',

object_name => 'EMP',

policy_name => 'SAL_AUDIT',

audit_condition => NULL, -- Equivalent to TRUE

audit_column => 'SAL',

statement_types => 'SELECT,INSERT,UPDATE,DELETE');

END;

/

-- Test the auditing.

CONN audit_test/password

SELECT * FROM emp WHERE empno = 9998;

INSERT INTO emp (empno, ename, sal) VALUES (9998, 'Bill', 1);

UPDATE emp SET sal = 10 WHERE empno = 9998;

DELETE emp WHERE empno = 9998;

ROLLBACK;

-- Check the audit trail.

CONN sys/password AS SYSDBA

SELECT sql_text FROM dba_fga_audit_trail;

SQL_TEXT

--------------------------------------

SELECT * FROM emp WHERE empno = 9998

INSERT INTO emp (empno, ename, sal) VALUES (9998, 'Bill', 1)

UPDATE emp SET sal = 10 WHERE empno = 9998

DELETE emp WHERE empno = 9998

4 rows selected.

-- Drop the policy.

CONN sys/password AS SYSDBA

BEGIN

DBMS_FGA.drop_policy(

object_schema => 'AUDIT_TEST',

object_name => 'EMP',

policy_name => 'SAL_AUDIT');

END;

/

oracle audit_actions,Oracle Audit 功能的使用和说明相关推荐

  1. oracle设置密码复杂度、设置oracle超时退出的功能

    查看oracle是否启用密码复杂度: select limit from dba_profiles where RESOURCE_NAME='PASSWORD_VERIFY_FUNCTION' and ...

  2. oracle实现分段,用Oracle分段空间管理功能改进数据库性能

    如果Oracle数据库表出现大量碎片数据,则会浪费磁盘空间和严重影响性能.这时可以使用Oracle分段空间管理功能,特别是Oracle数据库分段压缩功能. 更新或删除表的记录,会在数据块中形成许多的空 ...

  3. oracle 11g的audit导致system表空间快速增长的问题

    oracle 11g的audit导致system表空间快速增长的问题         分类:             oracle              2012-03-23 16:20     ...

  4. oracle—ebs_采购功能点操作手册,oracle—EBS_采購功能点操作手册.doc

    oracle-EBS_采購功能点操作手册 PO模块功能点操作手册 作者:韩业邦 李亚军 创建日期:2012年3月6日 更新日期:2012年3月7日 版本:1.0 文档控制 更新记录 版本日期姓名说明1 ...

  5. ORACLE EBS中附件功能的使用

    简要说明: 应用开发员>附件 定义文档实体Document Entities,将要加附件中的表在这里注册 定义单据分类Document Categories,将单据做一个分类 定义附件功能Doc ...

  6. oracle中触发器的创建,Oracle触发器创建及其功能

    Oracle触发器创建及其功能 下面的文章主要介绍的是如何创建Oracle触发器,同时介绍了Oracle触发器的功能.语法,而且通过具体的例子可以让大家更深入的`掌握. 1.创建表t1 :create ...

  7. oracle撤销段的功能,oracle撤销表空间和回滚段

    /* 撤销表空间 */ 通过使用撤销技术,能够为Oracle数据库提供以下功能: * 使用ROLLBACK语句撤销事务 * 进行数据库恢复 * 提供数据的读一致性 Oracle强烈建议DBA在Orac ...

  8. 优酷java_youtubie 仿优酷的视频网站,采用JAVA开发,支持Oracle数据库。主要功能包含注册登录, 上传 Jsp/Servlet 238万源代码下载- www.pudn.com...

    文件名称: youtubie下载 收藏√  [ 5  4  3  2  1 ] 开发工具: Java 文件大小: 12657 KB 上传时间: 2015-04-23 下载次数: 1 详细说明:仿优酷的 ...

  9. 查看oracle是否开闪回,开启 oracle 的闪回功能

    查看是否开启闪回 SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ NO 查看是否配置了db_r ...

  10. php对应哪个oracle版本,Oracle 版本说明

    Oracle 的版本号很多,先看11g的一个版本号说明: 注意: 在Oracle 9.2 版本之后, oracle 的maintenance release number 是在 Oracle的版本号很 ...

最新文章

  1. c++ list 容器
  2. Ex 2_5 求解递推式..._第三次作业
  3. Codeforces Round #619 (Div. 2) F. Super Jaber 多源bfs + 思维转换
  4. Protocol Buffer技术详解(C++实例)
  5. SQL Server 执行 字符串
  6. oracle ro,ORACLE学习笔记一
  7. yum install rpm包时报错
  8. wpf之代码给grid添加内容
  9. mxonline实战14,全局搜索,修改个人中心页面个人资料信息
  10. oracle ADF 代码标准
  11. windows批量ping脚本
  12. 隐藏计算机关机键,关机快捷键有哪些?电脑Windows快捷关机最全方法图文详解
  13. Win7下载安装Mongodb教程
  14. linux中-f的含义,linux 下shell中if的“-e,-d,-f”的含义
  15. 【直线检测】基于LSD实现直线检测含Matlab源码
  16. 如何破解百度文库的防复制功能
  17. python3 爬取今日头条文章(巧妙避开as,cp,_signature)
  18. ESP32CAM摄像头图像实时传输
  19. [渝粤教育] 西南科技大学 电子信息工程专业导论 在线考试复习资料
  20. VLC-2.2.6命令行帮助文件

热门文章

  1. 网络直播与营销“合二为一”
  2. 服务器数据恢复成功案例(磁盘阵列恢复)
  3. eclipse下载完成了但是打不开
  4. Eclipse如何调试代码
  5. 3D变形:平移、旋转、缩放
  6. ECS Windows服务器通过ie下载提示当前安全设置不允许下载该文件
  7. Vue单页面与多页面的区别
  8. 综述:图像风格化算法最全盘点 | 内附大量扩展应用
  9. mta android 网速监控,网速监控
  10. Ubuntu实时监控网速、CPU、内存