Wednesday 14 September 2011

Auditing failed INSERT statements and their authors

Question:
A particular table has been accessed by different users. I want to audit all the failed INSERT statments and the user who had tried to INSERT into the table. How do I do that?
Answer:
First of all, I encourage to investigate the built-in auditing capabilities of Oracle, such as Fine Grained Auditing (FGA). If you can utilize features already provided by Oracle, why write something yourself?
If you are going to write your own solution, then you should consider implementing BEFORE INSERT and AFTER INSERT triggers that are themselves autonomous transactions. With this combination, you can easily identify an attempt to insert (BEFORE INSERT fired) that did not complete (the corresponding AFTER INSERT trigger was not fired).
Click here to view and run a script I put together to demonstrate the use of these triggers and autonomous transactions to solve your problem

No comments:

Post a Comment