keycloak/keycloak

Keycloak in kubernetes crashes on startup with "unable to obtain isolated JDBC connection"

已關閉

#42,778 建立於 2025年9月19日

 (13 則留言) (6 個反應) (0 位負責人)Java (8,346 個分叉)batch import
area/dist/quarkushelp wantedkind/bugpriority/normalstatus/auto-bumpstatus/auto-expirestatus/bumped-by-botteam/cloud-native

倉庫指標

星標
 (34,398 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

core

Describe the bug

When starting up as a kubernetes deployment, keycloak crashes with the error message:

2025-09-19 17:12:16,462 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: org.hibernate.exception.GenericJDBCException: unable to obtain isolated JDBC connection [Acquisition timeout while waiting for new connection] [n/a]

The postgres database logs shows no indication of a db connection, failed or otherwise. I initially encountered a similar error to this using a slightly different configuration that the minimal configuration I will now present.

Minimal steps to reproduce are identical to the kubernetes "getting started" instructions, https://www.keycloak.org/getting-started/getting-started-kube.

I initially encountered problems under slightly different conditions, in which the username, password, and database were set to 'keycloak' but a connection failed, with postgres yielding a stream of 'FATAL: role "postgres" does not exist' errors. I am not certain that the error in that situation and in the minimal example are the same bug, but it is suspicious that they are both occurring at the same time.

The keycloak error message in the non-minimal example is:

2025-09-19 13:55:30,940 WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: java.lang.NullPointerException: Cannot throw exception because the return value of "java.util.function.BiFunction.apply(Object, Object)" is null

The database itself is up and accessible, and I'm quite certain that the host name, connection url, and credentials are all correct.

Version

26.3.4

Regression

  • The issue is a regression

Expected behavior

  • Deploy kubernetes from a manifest
  • the keycloak application and database spin up and a connection is formed
  • keycloak api is accessible

Actual behavior

  • Deploy keycloak from manifest
  • keycloak fails to make a successful connection
  • keycloak enters crash loop

This resulting output is

keycloakDbOutputMinimal.txt keycloakOutputMinimal.txt

in the attached files.

How to Reproduce?

kubectl -n <my-namespace> create -f https://raw.githubusercontent.com/keycloak/keycloak-quickstarts/refs/heads/main/kubernetes/keycloak.yaml

This command is what is provided on the keycloak website in the link above, which results in an immediate crash loop.

Anything else?

No response

貢獻者指南