Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quarkus: How to connect replicated SQL database with read/write instances?

I want to connect a Qurkus/Hibernate-based application to a replicated PostgreSQL instance running in Google Cloud. Such a replication assumes there is a write instance and there are several read replicas.

I went through the Qurkus documentation but couldn't find a way to do it. There is a way to setup multiple data sources for different databases, but it is not what I need.

Question: How to configure read/write DB instances in Quarkus?

I am using Quarkus 1.11.3.Final.

like image 400
Sasha Shpota Avatar asked Dec 18 '25 21:12

Sasha Shpota


2 Answers

I haven’t tried using cloud SQL but reading the docs you would want to explore how jdbc is configured.

So try follow https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/blob/main/docs/jdbc-postgres.md and use that with Quarkus. See https://quarkus.io/guides/datasource on how to configure jdbc.

like image 87
Max Rydahl Andersen Avatar answered Dec 20 '25 10:12

Max Rydahl Andersen


I'm working on a guide for Cloud SQL, it's not yet finised as there is some issue with dev mode that we want to handle before adding the guide.

So, you need to add the Cloud SQL JDBC socket lib.

Then configure the socket factory of PostreSQL via the additional JDBC properties:

quarkus.datasource.db-kind=other
quarkus.datasource.jdbc.url=jdbc:postgresql:///mydabatabe
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

Everything is explained here: https://github.com/quarkusio/quarkus/pull/15783/files#diff-a52617b3eb5153201582a0aa218aca7bded4e1712c3566c8f052737139c716c9R221

As I said, this will not work in dev mode so you must use a local database for using dev mode.

Please provides feedback if it didn't work for you

like image 44
loicmathieu Avatar answered Dec 20 '25 09:12

loicmathieu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!