简体   繁体   English

AUTONOMOUS_TRANSACTION

[英]AUTONOMOUS_TRANSACTION

I was thinking of using AUTONOMOUS_TRANSACTION Pragma for some logging in a batch process. 我正在考虑使用AUTONOMOUS_TRANSACTION Pragma进行批处理中的某些日志记录。 Does anyone have any experience with this ? 有人对这个有经验么 ? If so any pros and cons would be appreciated. 若有,任何利弊都会受到赞赏。

IMO Autonomous Transactions are particularly adapted to logging: they run independently from the main session, meaning you can write in a table, commit or rollback changes without affecting the main transaction. IMO自治事务特别适用于日志记录:它们独立于主会话运行,这意味着您可以在表中写入,提交或回滚更改而不会影响主事务。

They also add little overhead: if you run big statements and add an autonomous transaction between each statement the performance cost will be negligible. 它们也增加了很少的开销:如果你运行大语句并在每个语句之间添加一个自治事务,那么性能成本可以忽略不计。

There is also a side-effect that you may find interesting: since the autonomous transactions are in independant sessions from the calling transaction, you can follow the progression of your main process as it is running. 还有一个您可能感兴趣的副作用:由于自主事务处理来自调用事务的独立会话,因此您可以跟踪主进程在运行时的进度。 You don't have to wait for the main transaction to finish: you can query the logging table as it is filled by the autonomous transactions. 您不必等待主事务完成:您可以查询日志表,因为它由自治事务填充。

Obviously, any logging done in an autonomous transaction will remain in the database even if the main transaction rolls back. 显然,即使主事务回滚,在自治事务中完成的任何日志记录都将保留在数据库中。 For logging this is probably what you want, but it is important to remember that a log record saying "inserted row X into table Y" doesn't mean that that insert actually got committed. 对于日志记录,这可能是您想要的,但重要的是要记住,“将行X插入表Y”的日志记录并不意味着该插入实际上已提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM