Re: [External] JDBC Postgres Failover with quorum based synchronous replication

From: Debraj Manna <subharaj(dot)manna(at)gmail(dot)com>
To: Vijaykumar Jain <vjain(at)opentable(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: [External] JDBC Postgres Failover with quorum based synchronous replication
Date: 2018-06-17 09:12:46
Message-ID: CAF6DVKOaiRaPr-N0Vkg08CbC0Ws8quoGahSgYyCMhVVva8AxBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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 <vjain(at)opentable(dot)com>
wrote:

> I guess the distinction between master and secondary logic can be looked
> up here(isMaster)
> https://github.com/pgjdbc/pgjdbc/blob/f78a639d1ed3c64e80e1fa107691b4
> af5945cb84/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 <subharaj(dot)manna(at)gmail(dot)com>
> 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 replication<https://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 here<https://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 ?
>
> Thanks,
>
>
>
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Vijaykumar Jain 2018-06-17 10:23:17 Re: [External] JDBC Postgres Failover with quorum based synchronous replication
Previous Message Vijaykumar Jain 2018-06-17 08:41:03 Re: [External] JDBC Postgres Failover with quorum based synchronous replication