<p>I have a need to do auditing all database activity regardless of whether it came from application or someone issuing some sql via other means. So the auditing must be done at the database level. The database in question is Oracle. I looked at doing it via Triggers and also via something called Fine Grained Auditing that Oracle provides. In both cases, we turned on auditing on specific tables and specific columns. However, we found that Performance really sucks when we use either of these methods.</p>

<p>Since auditing is an absolute must due to regulations placed around data privacy, I am wondering what is best way to do this without significant performance degradations. If someone has Oracle specific experience with this, it will be helpful but if not just general practices around database activity auditing will be okay as well. </p>

[{'answer_id': 67623, 'author': 'Colin Coghill', 'author_id': 10285, 'author_profile': 'https://Stackoverflow.com/users/10285', 'pm_score': 3, 'selected': True, 'text': "<p>I'm not sure if it's a mature enough approach for a production\nsystem, but I had quite a lot of success with monitoring database\ntraffic using a network traffic sniffer.</p>\n\n<p>Send the raw data between the application and database off to another\nmachine and decode and analyse it there. </p>\n\n<p>I used PostgreSQL, and decoding the traffic and turning it into\na stream of database operations that could be logged was relatively\nstraightforward. I imagine it'd work on any database where the packet\nformat is documented though.</p>\n\n<p>The main point was that it put no extra load on the database itself.</p>\n\n<p>Also, it was passive monitoring, it recorded all activity, but \ncouldn't block any operations, so might not be quite what you're looking for.</p>\n"}, {'answer_id': 2612535, 'author': 'Opus', 'author_id': 313312, 'author_profile': 'https://Stackoverflow.com/users/313312', 'pm_score': 1, 'selected': False, 'text': '<p>There is no need to "roll your own".  Just turn on auditing:</p>\n\n<ol>\n<li>Set the database parameter AUDIT_TRAIL = DB.</li>\n<li>Start the instance.</li>\n<li>Login with SQLPlus.</li>\n<li>Enter the statement <pre>audit all;</pre>This turns on auditing for many critical DDL operations, but DML and some other DDL statements are still not audited.</li>\n<li>To enable auditing on these other activities, try statements like these:<pre>audit alter table; -- DDL audit\naudit select table, update table, insert table, delete table; -- DML audit</pre></li>\n</ol>\n\n<p>Note:  All "as sysdba" activity is ALWAYS audited to the O/S.  In Windows, this means the Windows event log.  In UNIX, this is usually $ORACLE_HOME/rdbms/audit.</p>\n\n<p>Check out the <a href="http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm" rel="nofollow noreferrer">Oracle 10g R2 Audit Chapter</a> of the Database SQL Reference.</p>\n\n<p>The database audit trail can be viewed in the SYS.DBA_AUDIT_TRAIL view.</p>\n\n<p>It should be pointed out that the internal Oracle auditing will be high-performance by definition.  It is designed to be exactly that, and it is very hard to imagine anything else rivaling it for performance.  Also, there is a high degree of "fine-grained" control of Oracle auditing.  You can get it just as precise as you want it.  Finally, the SYS.AUD$ table along with its indexes can be moved to a separate tablespace to prevent filling up the SYSTEM tablespace.</p>\n\n<p>Kind regards,\nOpus</p>\n'}, {'answer_id': 2623211, 'author': 'David Mann', 'author_id': 120052, 'author_profile': 'https://Stackoverflow.com/users/120052', 'pm_score': 1, 'selected': False, 'text': '<p>If you want to record copies of changed records on a target system you can do this with Golden Gate Software and not incur much in the way of source side resource drain. Also you don\'t have to make any changes to the source database to implement this solution. </p>\n\n<p>Golden Gate scrapes the redo logs for transactions referring to a list of tables you are interested in. These changes are written to a \'Trail File\' and can be applied to a different schema on the same database, or shipped to a target system and applied there (ideal for reducing load on your source system). </p>\n\n<p>Once you get the trail file to the target system there are some configuration tweaks you can set an option to perform auditing and if needed you can invoke 2 Golden Gate functions to get info about the transaction:</p>\n\n<p>1) Set the INSERTALLRECORDS Replication parameter to insert a new record in the target table for every change operation made to the source table. Beware this can eat up a lot of space, but if you need comprehensive auditing this is probably expected. </p>\n\n<p>2) If you don\'t already have a CHANGED_BY_USERID and CHANGED_DATE attached to your records, you can use the Golden Gate functions on the target side to get this info for the current transaction. Check out the following functions in the GG Reference Guide:\nGGHEADER("USERID")\nGGHEADER("TIMESTAMP")</p>\n\n<p>So no its not free (requires Licensing through Oracle), and will require some effort to spin up, but probably a lot less effort/cost than implementing and maintaining a custom solution rolling your own, and you have the added benefit of shipping the data to a remote system so you can guarantee minimal impact on your source database. </p>\n'}, {'answer_id': 5468408, 'author': 'ag112', 'author_id': 531321, 'author_profile': 'https://Stackoverflow.com/users/531321', 'pm_score': 0, 'selected': False, 'text': '<p>if you are using oracle then there is feature called CDC(Capture data change) which is more performance efficient solution for audit kind of requirements.</p>\n'}]
['https://Stackoverflow.com/questions/67557', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9149/']