Db2 – Applying audit policy on multiple auditing subject or object

auditdb2

I have created a policy on execute category and I would like to know if this policy can be applied on multiple auditing subject or object. Since the execute category will generate many audit entries I would like to limit the results by applying this execute audit policy on specific user/table combination.

Is it possible?

Best Answer

Whilst the audit policy created by CREATE AUDIT POLICY is database-wide, it is applied to individual objects or roles by the AUDIT statement. For example, to audit statement executions (successful or otherwise) against a particular table:

CREATE AUDIT POLICY allexec CATEGORIES EXECUTE STATUS BOTH;
COMMIT;
AUDIT TABLE mytable USING POLICY allexec;
COMMIT;

To audit statements executed by a particular role:

AUDIT ROLE somerole USING POLICY allexec;
COMMIT;

The reason for all the COMMITs is that, as the docs note, "[a]n AUDIT-exclusive SQL statement must be followed by a COMMIT or ROLLBACK statement...". See audit policies for more information.