Kycloak not using KC_DB_URL_HOST but localhost

Hello,

I have a keycloak on a Kubernetes cluster (EKS). It’s manifest yaml file is set up with :slight_smile: - name: KC_DB
value: “postgres”

  • name: KC_DB_URL_DATABASE
    value: “keycloaxxxdb”
  • name: KC_DB_URL_HOST
    value: “jdbc:postgresql://xxxxx.xxxxx.xxxxx.rds.amazonaws.com”
  • name: KC_DB_URL_PORT
    value: “5432”
  • name: KC_DB_USERNAME
    value: “demoappuser”
  • name: KC_DB_PASSWORD
    value: “demoappuserpassword”

but keycloak tries to login to localhost:5432
org.postgresql.Driver] (agroal-11) Connection error: : org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

How do you start Keycloak? With --optimized flag? Then this won’t work, as KC_DB requires a build step.

The usage of environment variables seems odd.

Reading Configuring the database - Keycloak KC_DB_URL_HOST should template the jdbc connection string, but you’re setting an entirely new jdbc string. Does it log any parsing and fallback errors?

I’d either try to set KC_DB_URL_HOST to xxxxx.xxxxx.xxxxx.rds.amazonaws.com or just use KC_DB_URL as jdbc:postgresql://xxxxx.xxxxx.xxxxx.rds.amazonaws.com/keycloaxxxdb

2 Likes

Ah, yes, @ThoreKr is right, I didn’t see the jdbc:postgresql:// prefix in your KC_DB_URL_HOST param.

Many thanks to all of you.

It was inded a wrong way of setting KC_DB_URL.

I finally used KC_DB_URL instead of KC_DB_URL_HOST withe the correct jdbc format as jdbc:postgresql://xxxxx.xxxxx.xxxxx.rds.amazonaws.com/keycloaxxxdb