Keycloak启动时忽略--db-url选项,PostgreSQL连接失败求助
Keycloak 19.0.1连接PostgreSQL时忽略--db-url的问题
我在Ubuntu系统上尝试将Keycloak 19.0.1与PostgreSQL集成,执行了以下启动命令:
./kc.sh start-dev --http-port ${PORT} --db-url=jdbc:postgres://myurl.com/database --db=postgres --db-schema auth --db-username postgres --db-password password
但出现错误:
[org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread: keycloak-default) HHH000342: Could not obtain connection to query metadata: 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.
数据库不在localhost,但Keycloak仍尝试连接默认的localhost:5432,怀疑--db-url选项被忽略。
原因及解决方法
JDBC URL协议错误:你使用的
jdbc:postgres://不符合PostgreSQL JDBC驱动的规范,正确的协议应该是jdbc:postgresql://(多了ql后缀)。这个错误会导致Keycloak无法识别自定义URL,直接 fallback 到默认的localhost:5432连接。配置文件覆盖命令行参数:如果
conf/keycloak.conf文件中已经设置了db-url参数,命令行传入的参数会被配置文件覆盖。可以检查该配置文件,删除或修改其中的db-url项,或者在启动命令末尾添加--override-all强制使用命令行参数。缓存残留导致旧配置生效:Keycloak启动时会生成缓存文件存放在
data/目录中,如果之前有过连接localhost的启动记录,缓存可能残留旧配置。删除data/目录后再重新执行启动命令即可。
修正后的启动命令:
./kc.sh start-dev --http-port ${PORT} --db-url=jdbc:postgresql://myurl.com/database --db=postgres --db-schema auth --db-username postgres --db-password password
内容的提问来源于stack exchange,提问作者Twisted Tea
相关产品推荐
相关产品推荐

