Oracle SQL 查询日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7914354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL Query logging
提问by JMW
I'm using Oracle 11g Standard Edition.
我正在使用 Oracle 11g 标准版。
I would like to log all SQL queries, that are being executed by users, into a table.
我想将用户正在执行的所有 SQL 查询记录到一个表中。
How can this be done?
如何才能做到这一点?
采纳答案by APC
If you're using a modern version of the database (9i or later) and you have an Enterprise Edition license you can use Fine-Graining Auditing. It allows us to audit user queries at a very low level of granularity, through defined policies.
如果您使用的是现代版本的数据库(9i 或更高版本)并且您拥有企业版许可证,则可以使用细粒度审计。它允许我们通过定义的策略以非常低的粒度级别审计用户查询。
To capture SQL text and bind variables you will need to set the AUDIT_TRAIL parameter appropriately when adding an FGA Policy. Find out more.
要捕获 SQL 文本并绑定变量,您需要在添加 FGA 策略时适当地设置 AUDIT_TRAIL 参数。 了解更多。
"i'm using an 11g standard, so auditing functions are not supported."
“我使用的是 11g 标准,所以不支持审计功能。”
Not exactly. The AUDIT command is part of the standard Oracle build, but it only allows us to capture when a given user issues a SELECT against a given table. But, yes, to find out exactly whatthey are selecting requires Enterprise Edition license.
不完全是。AUDIT 命令是标准 Oracle 构建的一部分,但它只允许我们在给定用户对给定表发出 SELECT 时进行捕获。但是,是的,要准确了解他们的选择需要企业版许可证。
Also there is no ON SELECT trigger, so we cannot roll our own.
也没有 ON SELECT 触发器,所以我们不能自己滚动。
"So can i use AUDIT command in the standard edition? ... But then a consultant told me, that i cannot use it without paying enterprise license? "
“那我可以在标准版中使用AUDIT命令吗?......但后来一位顾问告诉我,我不支付企业许可证就不能使用它?”
Speaking as a consultant myself, I do have to say those guys don't always know what they are talking about.
作为一名顾问,我不得不说那些人并不总是知道他们在说什么。
So let's be clear:
所以让我们明确一点:
- the AUDIT command is part of Oracle SQL. It is usable with the Standard Edition. In fact since 11g it is enabled by default. It audits general activity. Find out more.
- Fine Grained Auditing is a PL/SQL package with is only usable if you have the Enterprise Edition. It allows us to audit user activity at a very low level. Find out more.
回答by mike
For QUICK, EASY logging of SQL, try my monitoring answer here. Not for long-term logging, but works great just to see what is going on in a small time window. :-)
要快速、轻松地记录 SQL,请在此处尝试我的监控答案。不适用于长期日志记录,但仅适用于查看小时间窗口内发生的情况。:-)