Jooq+hikariCP+Postgres-无法处理故障切换



我有一个spring-boot应用程序,可以读取/写入postgres数据库。我使用jooqhikariCP来管理数据库连接。我的应用程序连接到一个由两个Postgresql 14.5实例组成的patroni集群,一个是主实例,另一个是只读副本。

当服务正在处理数据并且我触发数据库中的故障切换时-杀死首领,选择新首领,然后把旧首领变成复制品——我开始遇到这样的例外

withnorg.jooq.exception.DataAccessException: SQL [delete from "public"."my_table" where "public"."my_table"."username" = ?]; ERROR: cannot execute DELETE in a read-only transaction

它看起来像是CCD_ 4驱动程序问题,其中它仍然使用到CCD_。

如何解决?

我的配置如下:

org.jooq:jooq:3.16.10
org.postgresql:postgresql:42.5.0
org.jooq:jooq-postgres-extensions:3.16.10
com.zaxxer:HikariCP:4.0.3
spring:
main:
allow-bean-definition-overriding: true
banner-mode: "off"
jooq:
sql-dialect: Postgres
jpa:
open-in-view: false
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: org.postgresql.Driver
url: "jdbc:postgresql://my-db-cluster:5432/my-database?tcpKeepAlive=true&ApplicationName=my-app"
username: ${DATASOURCE_USERNAME}
password: ${DATASOURCE_PASSWORD}
hikari:
minimumIdle: 0
maximumPoolSize: 10
auto-commit: false
autoconfigure:
exclude: org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration

我通过将&targetServerType=primary添加到jdbc url中找到了一个解决方案,如文档所示:https://jdbc.postgresql.org/documentation/use/

最新更新