Keycloak.X - number of database connections growing quickly until the DB server limit is hit

Hi there,

I’m playing around with Keycloak.X (Preview) on my local machine using postgresql (13) as database.

Starting and running the server seems to be quite simple but when I log in to the admin console and click around a little bit, e.g. quickly navigating between “Clients” and “Roles” the number of database connections increases quickly. Eventually it hits the DB server limit (around 100 according the the postgresql server settings) and then errors popup in keycloak.

This is a screenshot from pgadmin:

It seems to release idle connections sporadically/randomly. Eventually it does not prevent that the DB server connection limit is reached which results in errors.

I also tried to limit the number of max connections using --db.pool.max-size and then -Dquarkus.datasource.jdbc.max-size but both do not seem to have any effect.

Any idea what I’m doing wrong?

Kind regards,
Norman.

Hi, are you ussing this configuration as environment variables in docker?

Hi,

I tried both as command line option ( --db.pool.max-size and -Dquarkus.datasource.jdbc.max-size) as well as environment variables KC_DB_POOL_MAX-SIZE and KC_DB_POOL_MAX_SIZE. Without any noticable effect.

Besides the point that I cannot get the --db.pool.max-size parameter to work it still seems very odd that the number of idle DB connections sky-rockets to those heights for me being the only user logged in by just clicking around in the admin console. The wildfly version does not show this behavior.

So, any help appreciated here.

Regards,
Norman.

Hey @Norman,

By any chance, did you manage to find a solution to this issue? I have the same problem with the v18 of Keycloak and the Quarkus distribution with my PostgreSQL database

Thanks!

Hi @ccoeurderoy ,

Back then we disabled distributed transactions in keycloak. But since a couple of versions this issue seems to be fixed for us thus not requiring anymore to apply our “fix”.

Cheers,
Norman.

@Norman thank you for your reply! Well, I’ve also migrated to the v19 of Keycloak but I always have the same problem when I use the Keycloak admin API with client roles… Anyway I think I’m missing a configuration somewhere

Finally, we’ve found a wrong usage of Keycloak Admin REST API on our side increasing database connections! I don’t know why it wasn’t the case with the Wildfly distribution, at least it is solved now