From time to time questions arise about auditing DDL statements like CREATE TABLE and GRANT, and the answers are frequently the same:
- SQL Anywhere doesn't support triggers on DDL statements, and
- you can use SQL Anywhere's built-in audit feature.
- Auditing puts data in the transaction logs, and
- logs are hard to analyze on a timely basis, and besides,
- transaction logs are separate files not subject to the natural ACID durability protections offered by any product that calls itself a "database"... transaction logs can be (and often are) deleted at any time.
In fact, if you're serious about auditing DDL statements you want to audit them whether they succeed or fail... like a security camera that watches the loading dock 24-by-7 whether or not Walt and Jesse are successful stealing that barrel of methylamine.
What We Need
What we need is a CREATE EVENT TYPE DDLStatement that works asynchronously on its own connection, and is fired when a DDL statement has finished executing.With a corresponding EVENT_PARAMETER() call (or two), of course :)
Plus (maybe) a WHERE EVENT_CONDITION() predicate... or two... or three...
A restricted list of 't' values might be provided; e.g., 'grant' for all forms of the GRANT statement, and 'create table' for all forms of DDL that create rows in ISYSTAB including views.
CREATE EVENT e TYPE DDLStatement [ WHERE EVENT_CONDITION ( 'Type' ) = 't' -- very nice to have | WHERE EVENT_CONDITION ( 'Type' ) IN ( 't' [, 't'] ... -- nice to have | WHERE EVENT_CONDITION ( 'StatementText' ) LIKE 'string' ] -- would be way cool HANDLER BEGIN ... ... EVENT_PARAMETER ( 'StatementText' ) ... -- required... pointless without this ... ... EVENT_PARAMETER ( 'SQLCODE' ) ... -- very nice to have ... END;
The EVENT_PARAMETER and EVENT_CONDITION ( 'StatementText' ) calls would return whatever the server processed, not necessarily what the client sent... this is an audit tool, not a documentation or debugging tool (although it would be invaluable for both purposes :)
1 comment:
This seems like a good idea at first glance. I will pass it on to the big brains and see what they think.
Post a Comment