23ai新特性:Priority Transactions

从23ai开始,oracle通过事务优先级实现了一种自动回滚的事务机制。

Starting with Oracle Database 23ai, the database provides parameters to control when and which transactions holding rowlocks can be automatically rolled back. Oracle database rolls back the transaction but the session stays alive. The application must acknowledge the automatic rollback of the transaction by issuing a ROLLBACK SQL statement.

Applications can specify the priority of their transactions. If a low priority transaction blocks a high priority transaction on rowlocks, Oracle database will automatically roll back the low priority transaction to let the high priority transaction(s) progress.

The database administrator can configure the time after which the low priority transaction is rolled back.

Note that if a transaction is holding a rowlock and not blocking any transaction, such a transaction is never rolled back.

具体是如何实现事务优先级其实是通过一系列的控制参数实现的。

应用程序可以根据事务重要性通过alter session命令修改参数txn_priority来设置事务优先级,txn_priority有3个选项(默认HIGH):

  • LOW:If a LOW priority transaction is blocked for a row lock, Oracle database will not attempt to roll back the transaction holding the row lock irrespective of its priority.
  • MEDIUM:If a MEDIUM priority transaction is blocked for a row lock, Oracle database can roll back the transaction that is holding the row lock only if the holder is LOW priority.
  • HIGH:If a HIGH priority transaction is blocked for a row lock, Oracle database can roll back the transaction that is holding the row lock only if the holder is LOW or MEDIUM priority.

Oracle database never rolls back a HIGH priority transaction.

priority_txns_high_wait_target和priority_txns_medium_wait_target控制不同事务优先级的等待时间单位为秒

  • priority_txns_high_wait_target:specifies the maximum number of seconds that a HIGH priority transaction will wait for a row lock before the Priority Transactions feature rolls back a lower priority transaction holding the lock
  • priority_txns_medium_wait_target:specifies the maximum number of seconds that a MEDIUM priority transaction will wait for a row lock before the Priority Transactions feature rolls back a lower priority transaction holding the lock.

测试验证demo:

session 1:

session 2:

验证结果:

session 2在等待priority_txns_high_wait_target时间后,session 1的事务被自动回滚,但是session继续保留。alert中将打印自动终止事务的相关信息

session 1必须手动回滚才能继续后续操作

txn_auto_rollback_high_priority_wait_target和txn_auto_rollback_medium_priority_wait_target应该只是开发用的参数,设置并无作用

最终生效的是priority_txns_high_wait_target

此外在event、sysstat、v$transaction都增加了事务优先级的相关信息

  • v$transaction新增了txn_priority和priority_txns_wait_target字段
  • sysstat新增了txns rollback priority的相关统计
  • event细化了不同事务优先级下的TX row lock队列等待

还有一点非常奇怪,在low事务优先级手动rollback之后,后续的操作事务就会自动回滚了,不需要手动rollback。应该是功能还没完善,毕竟官方正式版本还未发布

 

 

 

 

 

 

此条目发表在Oracle分类目录,贴了, 标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注