Search code examples
javapostgresqlgoogle-cloud-platformjdbcquarkus

How to set database jdbc url for Google Cloud SQL on quarkus?


I am trying to put my PostgreSQL DB onto Google Cloud SQL but encounter an error. To reproduce the error I do the following:

  1. mvn install
  2. export GOOGLE_APPLICATION_CREDENTIALS=yyy.json
  3. java -jar target/quarkus-app/quarkus-run.jar

Which throws the following error:

org.postgresql.util.PSQLException: FATAL: database "XXX" does not exist

When looking at the official documentation of quarkus it mentions that I need to set the following properties:

quarkus.datasource.db-kind=other 
quarkus.datasource.jdbc.url=jdbc:postgresql:///XXX 
quarkus.datasource.jdbc.driver=org.postgresql.Driver
quarkus.datasource.username=quarkus
quarkus.datasource.password=quarkus
quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance=project-id:gcp-region:instance 
quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory=com.google.cloud.sql.postgres.SocketFactory 

I assume I did not enter the correct database name on the second line (quarkus.datasource.jdbc.url) What url should be given as a property? The public IP address, the connection name, ...?


Solution

  • Posting this as a community wiki so that others can benefit from it.


    As mentioned by @guillaume blaquiere:

    XXX must be the database name. When you create your Cloud SQL instance, it's a database engine with a default database and you can also create your own database.


    Reference: