Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to PostgreSQL DB is failing with native-image #30701

Closed
majoferenc opened this issue Jan 30, 2023 · 12 comments
Closed

Connecting to PostgreSQL DB is failing with native-image #30701

majoferenc opened this issue Jan 30, 2023 · 12 comments
Labels

Comments

@majoferenc
Copy link

majoferenc commented Jan 30, 2023

Describe the bug

When app deployed into k8s cluster, the application is not able to connect to PostgreSQL DB due to error Driver does not support the provided URL: jdbc:postgresql://config-db-postgresql-db:5432/my_database

Expected behavior

Driver should support correct jdbc URLs

Actual behavior

Driver will return error:

│ 2023-01-30 09:02:48,864 WARN  [io.agr.pool] (main) Datasource '<default>': Driver does not support the provided URL: jdbc:postgresql://config-db-postgresql-db:5432/my_database                                  
│ 2023-01-30 09:02:48,889 WARN  [io.agr.pool] (agroal-11) Datasource '<default>': Driver does not support the provided URL: jdbc:postgresql://config-db-postgresql-db:5432/my_database                             
│ 2023-01-30 09:02:48,890 WARN  [org.hib.eng.jdb.env.int.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: java.sql.SQLException: Driver does not support the provided URL: jdbc:postgresql://config-db-postgresql-db:5432/my_database                                                                                                                                      
│     at io.agroal.pool.ConnectionFactory.connectionSetup(ConnectionFactory.java:242)                                                                                                                              
│     at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:226)                                                                                                                             
│     at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:535)                                                                                                                          
│     at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:516)                                                                                                                          
│ 2023-01-30 09:02:48,925 INFO  [io.quarkus] (main) Installed features: [agroal, cache, cdi, config-yaml, hibernate-orm, hibernate-orm-panache, jaeger, jdbc-db2, jdbc-h2, jdbc-postgresql, keycloak-authorization, micrometer, narayana-jta, oidc, resteasy-reactive, resteasy-reactive-jackson, security, servlet, smallrye-context-propagation, smallrye-health, smallrye-openapi, smallrye-opentracing, spring-data-jpa, spring-di, spring-security, spring-web, swagger-ui, vertx]

The same app when running locally in dev mode can connect to postgresql database without issues.

How to Reproduce?

Steps to reproduce:

create a web app with jdbc connection
build application as native binary
deploy into container engine
try to configure jdbc connection to database system like postgresql

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.15.3.FINAL

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

Dependencies:

    implementation 'io.quarkus:quarkus-jdbc-postgresql'
    implementation 'io.quarkus:quarkus-agroal'

Our configuration in YAML:

quarkus:
  datasource:
    db-kind: ${CONFDB_DATABASE_KIND:postgresql}
    username: ${CONFDB_DATASOURCE_USERNAME:usernam}
    password: ${CONFDB_DATASOURCE_PASSWORD:password}
    jdbc:
      url: ${CONFDB_DATASOURCE_JDBC_URL:jdbc:postgresql://localhost:5432/my_database}
      max-size: ${CONFDB_CONNECTION_POOL_MAX_SIZE:2}
      min-size: ${CONFDB_CONNECTION_POOL_MIN_SIZE:2}

Environment variables in the container:

bash-4.4$ env | grep CONFDB
CONFDB_DATASOURCE_JDBC_URL=jdbc:postgresql://localhost/test
CONFDB_CONNECTION_POOL_MAX_SIZE=2
CONFDB_DATASOURCE_USERNAME=username
CONFDB_CONNECTION_POOL_MIN_SIZE=2
CONFDB_DATASOURCE_PASSWORD=password
CONFDB_DATABASE_KIND=postgresql
@gastaldi
Copy link
Contributor

My bet is that the default value needs to be escaped. What happens if you replace:

      url: ${CONFDB_DATASOURCE_JDBC_URL:jdbc:postgresql://localhost:5432/my_database}

with

      url: ${CONFDB_DATASOURCE_JDBC_URL}

?

@majoferenc
Copy link
Author

@gastaldi we tried that option, but still doesn't work, same error appears

@gastaldi
Copy link
Contributor

Can you remove the jdbc-db2 and the jdbc-h2 extensions from your project? It looks like a different driver is being used to connect to it

@gastaldi
Copy link
Contributor

Also if you could provide a sample reproducer project that would help a lot. I couldn't reproduce the issue following the steps above

@majoferenc
Copy link
Author

@majoferenc
Copy link
Author

majoferenc commented Jan 31, 2023

@gastaldi You were right, after removing jdbc-db2 and jdbc-h2 dependencies, we are getting following build issue, which is also present on the sample project:

> io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[1512](https://gitlab.ngncc.de/cocomat/oss-pfs/pfsipclusterquarkus/-/jobs/416257#L1512)  	[error]: Build step io.quarkus.agroal.deployment.AgroalProcessor#build threw an exception: io.quarkus.runtime.configuration.ConfigurationException: Unable to find a JDBC driver corresponding to the database kind 'postgres' for the default datasource. Either provide a suitable JDBC driver extension, define the driver manually, or disable the JDBC datasource by adding 'quarkus.datasource.jdbc=false' to your configuration if you don't need it.

@gastaldi
Copy link
Contributor

dbkind needs to be postgresql. See Table 1 in https://quarkus.io/guides/datasource#jdbc-datasource-2

@majoferenc
Copy link
Author

majoferenc commented Jan 31, 2023

Correct, now it works, thanks!
Looks like the issue is present only when multiple jdbc libraries are present in the project.
However, I believe this is legitimate use case, for example on our testing environment we are using PostgreSQL database, but on customer side DB2 is used, therefore this feature is necessary for us.

Maybe the answer is to use different profiles for that, but it could be limiting in some cases.

gastaldi added a commit to gastaldi/quarkus that referenced this issue Jan 31, 2023
This improves the error message when the DB Kind is not found.

```
Unable to find a JDBC driver corresponding to the database kind 'postgres' for the default datasource (available: 'postgresql'). Check if it's a typo, otherwise provide a suitable JDBC driver extension, define the
driver manually, or disable the JDBC datasource by adding 'quarkus.datasource.jdbc=false' to your configuration if you don't need it.
```

Based on feedback from quarkusio#30701 (comment)
@gastaldi
Copy link
Contributor

@geoand
Copy link
Contributor

geoand commented Jul 21, 2023

@gastaldi is there still something that needs to be done here or can we close the issue?

@gastaldi
Copy link
Contributor

@geoand nope, let's close it

@geoand
Copy link
Contributor

geoand commented Jul 21, 2023

👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants