java - 具有基于仲裁的同步复制的 JDBC Postgres 故障转移

标签 java postgresql jdbc

假设我正在使用 quorum based synchronous replication在 3 节点集群的 synchronous_standby_names 中的 ANYFIRST 中有 2 个节点名称。

我正在尝试从 postgres jdbc doc 中讨论的从属读取.

jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true

谁能告诉我

  1. 如何选择奴隶?是随机选择从属还是首选具有零滞后或最小滞后的从属?
  2. jdbc url 中是否有任何设置只选择零复制的从属,如果不存在这样的从属,则读取将发送给主控?

版本

  • Postgres - 10.4
  • Postgres JDBC 驱动程序 - 42.2.2

最佳答案

这已在 this 的 postgres 邮件列表中得到回答。线程。

No I guess there is no such option. Maybe you raise a PR if you can :)

what you can do at infra level is put your databases behind a Load balancer (like haproxy or nginx) and have a health check based on lag etc and only then Route the connections to that standby node else take it off the load balancer.

Regards, Vijay


From: Debraj Manna Sent: Sunday, June 17, 2018 2:42:46 PM To: Vijaykumar Jain Cc: pgsql-admin Subject: Re: [External] JDBC Postgres Failover with quorum based synchronous replication

Yes Vijaykumar you are right it is just a random shuffle while picking a slave.

https://github.com/pgjdbc/pgjdbc/blob/f78a639d1ed3c64e80e1fa107691b4af5945cb84/pgjdbc/src/main/java/org/postgresql/hostchooser/MultiHostChooser.java#L51

Is there a way I can specify in the connection parameters to pick a slave with zero lag else fall back to master?

On Sun, Jun 17, 2018 at 2:11 PM, Vijaykumar Jain > wrote: I guess the distinction between master and secondary logic can be looked up here(isMaster) https://github.com/pgjdbc/pgjdbc/blob/f78a639d1ed3c64e80e1fa107691b4af5945cb84/pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java and from within slaves iirc we did check the code and it is random shuffle and does not support any custom logic to pick any slaves. I might be wrong but I do remember looking it up in the source :)

Regards, Vijay


From: Debraj Manna > Sent: Sunday, June 17, 2018 11:31:32 AM To: pgsql-admin Subject: [External] JDBC Postgres Failover with quorum based synchronous replication

Hi

Let's say I am using quorum based synchronous replicationhttps://wiki.postgresql.org/wiki/New_in_postgres_10#Quorum_Commit_for_Synchronous_Replication either ANY or FIRST in synchronous_standby_names

I am trying to read from slave as discussed herehttps://jdbc.postgresql.org/documentation/head/connect.html.

jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true

Can someone let me know

  1. How does a slave is selected? Is a slave randomly selected or a slave is preferred which has zero lag or the minimum lag?
  2. Is there any setting in jdbc url which will only select the slave with zero replication and if no such slave exists then read will be sent to master ?

关于java - 具有基于仲裁的同步复制的 JDBC Postgres 故障转移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50894141/

相关文章:

java - java中基于字段值的List列表

java - RecyclerView LinearLayout 始终出现在其他元素之上

java - 如何在 JPA 和 EJB3 中使用 JDBC ClientInfo

node.js - 在 Sequelize 和 postgres 中插入和获取 JSON 数据

java - 属性 'driverClassName' 抛出异常;无法加载 JDBC 驱动程序类 [org.postgresql.Driver]

java - SQL 异常 : Too many database connection

java - 如何获取一系列字符? (字母)

sql - Postgresql比较varchar和时间类型

java - ResultSetMetaData.getColumnName 为 UNION 和非 UNION 查询返回不同的值

java - "com.mysql.jdbc.JDBC4Connection"的实例过多