We want to use CockroachDB instead of Postgres as database for Keycloak. CockroachDB is a distributed and lockless database.
Thus there is conceptually some differences with Postgres.
In case of concurrent transaction, it may happens that one of the transaction is aborted, the application is in charge of retry the transaction. The way to do it with cockroach is described in https://www.cockroachlabs.com/docs/stable/transactions.html#client-side-transaction-retries.
In summary, we have to create a SAVEPOINT just after the BEGIN transaction. Once all the statements are executed, release the SAVEPOINT.If the is a transaction fails due to concurrent Tx, we rollback to the savepoint and reexecute the statements.
This is the standard behavior of Cockroach, so we need to implement this mechanism for each DB calls.