Question

Project I'm involved relies on external services (SOA) and transaction management is turned on by default. However, in case of error, rolling back would cause some critical data loss like 'payment capture logging' (e.g. if code fails after capture has been made).

Is there a practical way to run a query outside current transaction? I always want external calls to be logged no matter what exceptions raise. I don't want to implement external logging service for convention. Savepoints won't take you there, maybe, another database connection needed for that moment?

Was it helpful?

Solution

Is there a practical way to run a query outside current transaction?

PostgreSQL doesn't natively support what you want, which is autonomous (sub)transactions.

You can simulate them with dblink, albeit clumsily. dblink does exactly what you suggested; it makes a connection from one PostgreSQL server to another. The connection may be the server connecting to its self.

If you can do this at the application level it's often better to do so, but dblink is certainly an option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top