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.
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
PREPAREd the transaction yet; 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 youBEGIN TRANSACTION FOR TWO PHASE COMMIT(imaginary syntax) or anything like that.You can test for
max_prepared_transactions> 0 inpg_settingsto see if prepared transactions are enabled, but there’s no way to know if 2PC will be used until it happens.