BUG: Unable to import data because the second Keycloak instance can't connect to cloud managed database

Hi there,

I have a Keycloak 12 application that is running in a container hosted on a Linux cloud server. It is connected to a remote managed cloud database. I only use PostgreSQL.

I have to import the Keycloak data that I previously, successfully, exported from another PostgreSQL database which is hosted on-premise into a new database.
I previously successfully imported the data into databases that I installed on-premise or in cloud Linux instances that have PostgreSQL.

I tested PostgreSQL 9, 12, and 13 without any problem with Keycloak 4.8.1.Final and Keycloak 12.

That said I have to use a cloud-managed database for my Keycloak 12 application.

I tried to connect to an OVH managed cloud database and I also tried with a DigitalOcean managed PostgreSQL cluster. My Keycloak application and the database are always hosted in the same region, in the same vpc by the same cloud-provider.

I perfectly access the managed databases and can administrate them from my browser with DBeaver and PgAdmin, however, importing the data simply does not work. I also perfectly access the psql remote terminal using ssh.

Unfortunately, when I start the second instance of Keycloak to import my data, it starts, then fails with the error “failed to connect to database”.
This only happens with managed DBs. The credentials, the address, the IP whitelist, etc, everything is OK, there is no error and no typo. I think that it is caused by the use of the binding port offset with the second Keycloak instance (which is necessary). Changing the value of the offset does nothing.

For the moment I temporarily use a cloud server where I installed PostgreSQL in production because I successfully import my data there. It is a DigitalOcean Droplet that exposes a PostgreSQL cluster, however, I need to find a solution to my problem with managed databases.

The DigitalOcean support team told me that they investigated and they did not find any reason that could cause my error. I got similar answers from OVH: they have no idea of what happens.

DigitalOcean closed the ticket telling me that I should ask for Keycloak support instead of cloud provider support.

Can you please help me?