I see that various comments in xact.c talk about start and end callbacks,
but only end seems to be implemented at the moment. I also can't find any
discussion about start of transaction callbacks in the mailing list
archives. Would a patch in this direction be of interest?

I was looking at this based on the discussion around extended transaction
logging for audit tools [1], there is another possible use of this session
information - in logical replication. There is a pattern among the users of
various logical replication / CDC of using user identity, application
identity or session flags as a way to suppress the logical replication of
some transactions. The primary interest seems to be in suppressing the
logical replication of bulk load or bulk update operations which are
dual-loaded into the two databases from a common source.

The existing infrastructure of XactCallback and pg_logical_emit_message()
seems to provide what's needed to tie this together, but only at the end
(COMMIT, ROLLBACK, PREPARE) of a transaction. It would be great for the
logical replication plugin to be able to make a decision at the start of a
large transaction to discard the transaction's content before incurring the
cost of staging the content and/or rolling back.

Thanks
Alastair

[1]
https://www.postgresql.org/message-id/flat/678FE75B.2020101%40acm.org#122d68fd45ea3012b7b5e49519e77b48

Reply via email to