1.数据库开启审计
alter system set audit_trail=db,extended scope=spfile;
shutdown immediate
startup
2.对某个表进行审计
connect / as sysdba
SQL> show user;
USER is "SYS"
SQL> audit select table by hxl by session;
Audit succeeded.
以上语句执行后在 dba_stmt_audit_opt 视图会有相应的记录
SQL> set linesize 1000;
SQL> select user_name, audit_option, success, failure from dba_stmt_audit_opts;
USER_NAME AUDIT_OPTION SUCCESS FAILURE
------------------------------ ---------------------------------------- ---------- ----------
HXL SELECT TABLE BY SESSION BY SESSION
3.使用hxl用户登录,查询该用户下的一个表
SQL> connect hxl/oracle
Connected.
SQL> select count(1) from tb_test;
COUNT(1)
----------
18
然后查询审计日志表,发现已经有记录了
SQL> Select Count(1) From dba_audit_trail Where obj_name In ('TB_TEST');
COUNT(1)
----------
1
4.取消审计
若我想把上面的审计取消,步骤如下
connect / as sysdba
SQL> noaudit select table by hxl;
Noaudit succeeded.
发现配置表dba_stmt_audit_opt相应的记录已经取消
退出原有的查询会话(必须退出,pl/sql需要关闭再登录,否则还会一直有审计),再次登陆查询就不会有审计记录了.
-- The End --