0

I'm currently working on a SpringBatch application that should insert some logs in case a certain type of error happens. The problem is that if the BatchJob fails, it automatically rollback everything done and that’s perfect, but it also rollback the error logs.

I need to achieve something similar to the AUTONOMOUS_TRANSACTION of Oracle while using PostgreSQL (14).

I’ve seen the DBLINK and it seem the only thing close to an alternative, but I have found some problems:

  • I need to avoid the connection string because the database host/port/name changes in the different environments, is it possible? I need to persist the data in the same database to technically I don’t need to connect to any other database but use the calling connection.

  • Is it possible to create a Function/Procedure that creates the takes care of all and I only have to call it Java side? Maybe this way I can somehow pass the connection data as a parameter in case that is not possible to avoid.

In a best case scenario I would be able to do something like:

dblink_exec(text sql);

That without arguments considers the same database where is been executed.

The problem is that I need this to be done without specifying any connection data, this will be inside a function on the executing db, in the same schema… that function will pass from one environment to the next one and the code needs to be the same so any name/user/pass needed must be avoided since they will change by environment. And since doing it in the same db and schema technically they can be inferred.

Thanks in advance!

At the moment I haven't try anything, I'm trying to get some information first.

  • Postgres does not have a anything directly corresponding to Oracle's Autonomous_Transaction. You can perhaps emulate it with a [Postgres dblink](https://%20https://www.postgresql.org/docs/current/contrib-dblink-function.html). – Belayer Feb 15 '23 at 00:54
  • @Belayer that’s exactly what I said, is there a way to execute a script to the same DB without naming or credentials? – RandomNando Feb 18 '23 at 09:32

0 Answers0