Oracle: Audit DMLs by specific user
February 18, 2016 Leave a comment
Ordinary auditing do not have option to indicate audit some activities done by specific user.
I mean, you cannot write the following:
audit insert on my_schema.my_table by my_user; <<—-not possible. The right statement is:
audit insert on my_schema.my_table by access;
or
audit insert on my_schema.my_table by session;
If I want to audit only activities done by my_user, one of the way is to create audit policy like the following;
begin
dbms_fga.add_policy(
object_schema=>’my_schema‘,
object_name=> ‘my_table‘,
policy_name=> ‘my_policy’,
audit_condition => ‘sys_context(”USERENV”,”CURRENT_USER”)=”MY_USER”’,
enable => TRUE,
statement_types => ‘INSERT, UPDATE, DELETE’,
audit_column_opts => dbms_fga.all_columns);
END;
So audit_condition gives the opportunity to check something and in this case we are checking user that is running statements indicated in statement_types option.
–Logs will be located here
SELECT * FROM dba_fga_audit_trail
–To see what policies we have
SELECT * FROM dba_audit_policies