question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres reactive configuration doesn't allow for arbitrary parameters on connect string

See original GitHub issue

Describe the bug

I’m trying to use Hibernate Reactive with Panache to connect the quarkus superheroes rest-heroes app to CockroachDB. The app (Quarkus 2.9.2) works fine with Dev Services or a postgres db I stand up on my own.

I’ve done a similar thing with the quarkus superheroes rest-villains app with JDBC & Hibernate ORM with Panache and everything works fine.

When connecting to the Cockroach DB DBaaS, it is mandatory that you include an options=--clister=<cluster_name> parameter, so I tried this configuration in the application.yml:

quarkus:
  datasource:
    username: myusername
    password: mypassword
    reactive:
      url: postgresql://free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/defaultdb?sslmode=require&options=--cluster%3Dheroes-db-2463
      postgresql:
        ssl-mode: require

Expected behavior

I would expect the options connection param to be passed along to the PG driver.

Actual behavior

Instead I get this error:

15:48:28 INFO  [or.hi.re.pr.im.ReactiveIntegrator] (JPA Startup Thread: default-reactive) HR000001: Hibernate Reactive

15:48:29 WARN  [or.hi.re.pr.se.ReactiveGenerationTarget] (vert.x-eventloop-thread-0) HR000021: DDL command failed [io.vertx.pgclient.PgException: FATAL: codeParamsRoutingFailed: missing cluster identifier (08004)]
15:48:29 WARN  [or.hi.re.pr.se.ReactiveGenerationTarget] (vert.x-eventloop-thread-0) HR000021: DDL command failed [io.vertx.pgclient.PgException: FATAL: codeParamsRoutingFailed: missing cluster identifier (08004)]

This indicated that the parameter was not included.

I did this as a test and it works fine:

@ApplicationScoped
public class StartupHelper {
  private final Vertx vertx;

  public StartupHelper(Vertx vertx) {
    this.vertx = vertx;
  }

  public void config(@Observes StartupEvent startupEvent) {
    Log.infof("Inside %s.config", getClass().getName());

    var connectOptions = new PgConnectOptions()
      .setPort(26257)
      .setHost("free-tier14.aws-us-east-1.cockroachlabs.cloud")
      .setDatabase("defaultdb")
      .setUser("myusername")
      .setPassword("mypassword")
      .setSslMode(SslMode.REQUIRE)
      .addProperty("options", "--cluster=heroes-db-2463");

    var poolOptions = new PoolOptions()
      .setMaxSize(5);

    var client = PgPool.client(this.vertx, connectOptions, poolOptions);

    client.query("DROP TABLE IF EXISTS Hero").execute()
      .onItem().invoke(() -> Log.info("Dropped Hero table"))
      .flatMap(r -> client.query("DROP SEQUENCE IF EXISTS hibernate_sequence").execute()
        .onItem().invoke(() -> Log.info("Dropped hibernate_sequence"))
      )
      .flatMap(r -> client.query("CREATE SEQUENCE hibernate_sequence START 1 INCREMENT 1").execute()
        .onItem().invoke(() -> Log.info("Created hibernate_sequence"))
      )
      .flatMap(r -> client.query("CREATE TABLE Hero (id int8 NOT NULL, level int4 NOT NULL, name VARCHAR(50) NOT NULL, otherName VARCHAR(255), picture VARCHAR(255), powers TEXT, PRIMARY KEY (id))").execute()
        .onItem().invoke(() -> Log.info("Created Hero table"))
      )
      .flatMap(r -> client.query("INSERT INTO hero(id, name, otherName, picture, powers, level) VALUES (nextval('hibernate_sequence'), 'Chewbacca', '', 'https://raw.githubusercontent.com/quarkusio/quarkus-super-heroes/characterdata/images/chewbacca--684239239428094811.jpg', 'Super Strength, Agility, Animal Attributes, Jaw Strength, Longevity, Marksmanship, Weapons Master', 30)").execute()
        .onItem().invoke(() -> Log.info("Inserted record into Hero table"))
      )
      .flatMap(r -> client.query("SELECT * FROM hero").execute()
        .onItem().invoke(ar -> Log.infof("Got %d rows", ar.size()))
      )
      .await().atMost(Duration.ofSeconds(20));

    client.close();
  }
}

Now the question is - how do I get that options parameter to stick in the Quarkus configuration? Is it a problem in the upstream Vert.x pg client? Or is there something we can/should do in Quarkus to solve for this? Maybe adding a config param in io.quarkus.reactive.pg.client.runtime.DataSourceReactivePostgreSQLConfig and read that in io.quarkus.reactive.pg.client.runtime.PgPoolRecorder?

How to Reproduce?

Steps to reproduce:

  1. You will need a cockroach labs account. I have a DB set up with credentials I can share if you would like. Please ping me privately (I don’t want to share publicly).
  2. Clone https://github.com/quarkusio/quarkus-super-heroes
  3. cd into rest-heroes
  4. Add the following to src/main/resources/application.yml:
    quarkus:  
      datasource:
        username: myusername 
        password: mypassword
        reactive:
         url: postgresql://free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/defaultdb?sslmode=require&options=--cluster%3Dheroes-db-2463
         postgresql:
           ssl-mode: require
    
  5. Run quarkus dev

Output of uname -a or ver

Darwin edeandrea-m1pro 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)
OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.9.2.Final

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

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /Users/edeandre/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4
Java version: 17.0.3, vendor: Eclipse Adoptium, runtime: /Users/edeandre/.sdkman/candidates/java/17.0.3-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
geoandcommented, Jun 2, 2022

so it looks like someone just needs to patch the extension to pass these on.

I think @edeandrea already signed up for it 😉

0reactions
edeandreacommented, Jun 2, 2022

@geoand / @Sanne I took a stab at this in #25931.

Read more comments on GitHub >

github_iconTop Results From Across the Web

34.1. Database Connection Control Functions - PostgreSQL
This function opens a new database connection using the parameters taken from the string conninfo . The passed string can be empty to...
Read more >
Reactive SQL Clients - Quarkus
In this guide, you will learn how to implement a simple CRUD application exposing data stored in PostgreSQL over a RESTful API. Extension...
Read more >
Use Spring Data R2DBC with Azure Database for PostgreSQL
Learn how to use Spring Data R2DBC with an Azure Database for PostgreSQL database.
Read more >
pgjdbc/r2dbc-postgresql: Postgresql R2DBC Driver - GitHub
Any other value specifies the cache size. options, A Map<String, String> of connection parameters. These are applied to each database connection created by...
Read more >
Spring Data R2DBC - Reference Documentation
R2DBC is the acronym for Reactive Relational Database Connectivity. ... + Note that the JavaConfig variant does not configure a package ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found