审计相关参数:
Audit_sys_operations
默认为false,当设置为true时,所有sys用户(包括以sysdba, sysoper身份登录的用户)的操作都会被记录,audit trail不会写在aud$表中,这个很好理解,
如果数据库还未启动aud$不可用,那么像conn /as sysdba这样的连接信息,只能记录在其它地方。如果是windows平台,audti trail会记录在windows的事件管理中,
如果是linux/unix平台则会记录在audit_file_dest参数指定的文件中
Audit_trail
None:是默认值,不做审计;
DB:将audit trail 记录在数据库的审计相关表中,如aud$,审计的结果只有连接信息;
DB,Extended:这样审计结果里面除了连接信息还包含了当时执行的具体语句;
OS:将audit trail 记录在操作系统文件中,文件名由audit_file_dest参数指定;
XML:10g里新增的。
XML,Extended
注:这两个参数是static参数,需要重新启动数据库才能生效
官方文档解析
DB Enables database auditing and directs all audit records to the database audit trail (SYS.AUD$), except for records that are
always written to the operating system audit trail
XML All elements of the AuditRecord node except Sql_Text and Sql_Bind will be printed to the operating system XML audit file.
DB,EXTENDED Does all actions of AUDIT_TRAIL=DB and also populates the SQL bind and SQL text CLOB-type columns of the SYS.AUD$
table, wherever possible. (These two columns are populated only when this parameter is specified.)
XML,EXTENDED Does all actions of AUDIT_TRAIL=XML and also populates the SQL bind and SQL text CLOB-type columns of the SYS.AUD$ table,
wherever possible. (These columns are populated only when this parameter is specified.)
OS Enables database auditing and directs all audit records to an operating system file
NONE Disables standard auditing (This value is the default.)
审计信息存放到db或os,各有优劣之处;os可以减少db的负担,且在db down了之后仍可查看,但管理不方便,且只要有os权限的人员都可以查看及篡改;
db,信息可更详细,查看方便,但容易给db额外的负担,且在数据库损害的情况下,审计信息同时丢失
审计级别
开启审计功能后,可在三个级别对数据库进行审计:Statement(语句)、Privilege(权限)、object(对象)
Statement
语句审计,对某种类型的SQL语句审计,不指定结构或对象。比如audit table 会审计数据库中所有的create table,droptable,truncate table语句,
alter session by test;--会审计test用户所有的数据库连接。
只审计某种类型的SQL语句,可对特定用户,也可所有用户。
AUDIT sql_statements [by user_name] [by session|access]
[whenever [not] successful]
SQL> audit select table by scott by access; # 审计soctt的所有select操作
SQL> audit table by access; 审计TABLE操作,包括CREATE/DROP/TRUNCATE
查看当前作了哪些审计
SQL> SELECT USER_NAME,AUDIT_OPTION,SUCCESS,FAILURE
FROM DBA_STMT_AUDIT_OPTS;
查看审计结果
SQL> select USERNAME,SQL_TEXT,TIMESTAMP from dba_audit_trail;
取消审计
SQL> noaudit table;
SQL> audit all on scott.emp; # 审计对scott.emp表的所有操作
审计的一些其他选项
by access / by session
by access 每一个被审计的操作都会生成一条audit trail。
by session 一个会话里面同类型的操作只会生成一条audit trail,默认为by session。
If you use the BY SESSION clause when directing audit records to the operating system audit trail, then Oracle Database generates and stores an audit record each time an access is made. Therefore, in this auditing configuration, BY SESSION is equivalent to BY ACCESS.(如果audit文件写在os时,by session 和 by access相同)
whenever [not] successful
whenever successful 操作成功(dba_audit_trail中returncode字段为0) 才审计,
whenever not successful 反之。省略该子句的话,不管操作成功与否都会审计。
audit select table
和审计相关的视图
dba_audit_trail:保存所有的audit trail,实际上它只是一个基于aud$的视图。其它的视图
dba_audit_session,dba_audit_object,dba_audit_statement都只是dba_audit_trail的一个子集。
dba_stmt_audit_opts:可以用来查看statement审计级别的audit options,即数据库设置过哪些statement级别的审计。dba_obj_audit_opts,dba_priv_audit_opts视图功能与之类似
all_def_audit_opts:用来查看数据库用on default子句设置了哪些默认对象审计。
取消审计
将对应审计语句的audit改为noaudit即可,
如audit session whenever successful
对应的取消审计语句为noaudit session whenever successful
清理审计
a. DELETE FROM SYS.AUD$;
DELETE FROM SYS.AUD$ WHERE obj$name='EMP';
b. Truncate SYS.AUD$
审计归档
a. INSERT INTO table SELECT ... FROM SYS.AUD$ ...
b. export
truncate 或者 delete sys.aud$ 表
在delete 之前,可以先把aud$表exp备份一下,注意,不要直接exp,先创建一张临时表,然后将临时表exp。
sql>create table audit_record tablespace users as select * from sys.aud$;
然后exp:
exp tables=AUDIT_RECORD file=audit_record.dmp
最后delete 数据:
sql>delete from sys.aud$;
或者删除指定表的审计:
sql>delete from sys.aud$ whereobj$name='&table_nmae';
注意,delete 不会释放system表空间。 可以使用truncate table:
sql>truncate table sys.aud$
将审计相关的表移动到其他表空
由于AUD$表等审计相关的表存放在SYSTEM表空间,因此为了不影响系统的性能,保护SYSTEM表空间,最好把AUD$移动到其他的表空间上。可以使用下面的语句来进行移动:
sql>connect / as sysdba;
sql>alter table aud$ move tablespace<new tablespace>;
sql>alter index I_aud1 rebuild onlinetablespace <new tablespace>;
SQL> alter table audit$ move tablespace<new tablespace>;
SQL> alter index i_audit rebuild onlinetablespace <new tablespace>;
SQL> alter table audit_actions movetablespace <new tablespace>;
SQL> alter index i_audit_actions rebuildonline tablespace <new tablespace>;
也可以用DBMS_AUDIT_MGMT实现迁移
conn / as sysdba
BEGIN
DBMS_AUDIT_MGMT.SET_AUDIT_TRAIL_LOCATION(audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_DB_STD,
audit_trail_location_value => 'USERS');
END;
/
验证DBMS_AUDIT_MGMT效果
SQL> select segment_name,tablespace_name from dba_segments where
segment_name in('AUD$','SYS_IL0000000384C00040$$','SYS_IL0000000384C00041$$', 'AUDIT$','I_AUDIT','AUDIT_ACTIONS','I_AUDIT_ACTIONS');
SQL> BEGIN
DBMS_AUDIT_MGMT.SET_AUDIT_TRAIL_LOCATION(audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_DB_STD,
audit_trail_location_value => 'USERS');
END;
/
SQL> select segment_name,tablespace_name from dba_segments where segment_name in('AUD$','SYS_IL0000000384C00040$$','SYS_IL0000000384C00041$$',
'AUDIT$','I_AUDIT','AUDIT_ACTIONS','I_AUDIT_ACTIONS');
2.该包可以实现在线迁移,特别是在高业务的系统中,可以实现在线迁移,而人工的move操作不能实现在线处理
3.对于AUD$对象,如果登录审计数据不是非常重要,可以通过truncate来解决一时的问题,在业务高的系统,可能truncate不能马上操作成功,可以尝试使用11gr2的新特性alter session set ddl_lock_timeout = 10;来实现自动ddl尝试
4.如果确定不需要登录审计功能,可以通过设置audit_trail=none来关闭(需要重启实例)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24486203/viewspace-1808657/
,如需转载,请注明出处,否则将追究法律责任。