简体   繁体   中英

AUTONOMOUS_TRANSACTION

I was thinking of using AUTONOMOUS_TRANSACTION Pragma for some logging in a batch process. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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