简体   繁体   English

如何在触发器中检测预备事务

[英]How to detect a Prepared Transaction inside a trigger

I have a problem with existing database code (a trigger) that call a function trigger that use the NOTIFY command, which is not supported in the context of a prepared transaction . 我现有的数据库代码(触发器)有问题,这些代码调用使用NOTIFY命令的函数触发器,这在准备好的事务的上下文中不受支持。

My question is simple : from the function trigger, is there a way to detect that we are in the context of a prepared transaction ? 我的问题很简单:从函数触发器中,有没有一种方法可以检测到我们处于准备好的事务中?

Thanks in advance. 提前致谢。

There is no way to detect that the current transaction will be committed using prepared transactions and two-phase commit, because you haven't PREPARE d the transaction yet; 有没有办法来检测使用准备好的事务和两阶段提交,目前的交易将被提交,因为你没有PREPARE尚未d交易; the transaction has no idea it's going to be subjected to two-phase commit until after your trigger runs. 事务不知道它将执行两阶段提交,直到触发器运行之后。 PostgreSQL doesn't require that you BEGIN TRANSACTION FOR TWO PHASE COMMIT (imaginary syntax) or anything like that. PostgreSQL不需要您开始进行BEGIN TRANSACTION FOR TWO PHASE COMMIT (虚构语法)或类似的BEGIN TRANSACTION FOR TWO PHASE COMMIT

You can test for max_prepared_transactions > 0 in pg_settings to see if prepared transactions are enabled , but there's no way to know if 2PC will be used until it happens. 您可以在pg_settings测试max_prepared_transactions > 0来查看是否启用了准备好的事务,但是直到发生2PC之前,您无法知道是否将使用2PC。

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

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