public inbox for [email protected]  
help / color / mirror / Atom feed
Pg jdbc DNS failover
2+ messages / 2 participants
[nested] [flat]

* Pg jdbc DNS failover
@ 2023-11-21 09:07 Nikolay Prokofiev <[email protected]>
  2023-11-21 13:07 ` Re: Pg jdbc DNS failover Dave Cramer <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Nikolay Prokofiev @ 2023-11-21 09:07 UTC (permalink / raw)
  To: [email protected]

Hi. According to pgjdbc documantation
<https://jdbc.postgresql.org/documentation/use/#connection-fail-over;, the
driver supports failover when ip addresses and ports of host are comma
separated, like this:
jdbc:postgresql://my-db-host-slave-1:5432,my-db-host-master-1:5432/database?targetServerType=primary
.

But it's not convenient, because we use k8s for pg, and there may be more
slaves added and master ip may be changed.

I want to store all my hosts in DNS and to specify one hostname like this:
jdbc:postgresql://my-db-host.local:5432/database?targetServerType=primary

I have a dns record with 2 ip addresses:

$ nslookup my-db-host.local
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
Name: my-db-host-slave-1
Address: 192.168.10.21
Name: my-db-host-master-1
Address: 192.168.11.25

and I tried to specify it like this:
jdbc:postgresql://my-db-host.local:5432/database?targetServerType=primary.

But this way it only picks the first ip - slave and fails with
org.postgresql.util.PSQLException:
Could not find a server with specified targetServerType: primary

Is there any workaround for using dns failover? May be some options in
connection pools if driver does not support that?


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Pg jdbc DNS failover
  2023-11-21 09:07 Pg jdbc DNS failover Nikolay Prokofiev <[email protected]>
@ 2023-11-21 13:07 ` Dave Cramer <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Cramer @ 2023-11-21 13:07 UTC (permalink / raw)
  To: Nikolay Prokofiev <[email protected]>; +Cc: [email protected]

On Tue, 21 Nov 2023 at 04:07, Nikolay Prokofiev <[email protected]>
wrote:

> Hi. According to pgjdbc documantation
> <https://jdbc.postgresql.org/documentation/use/#connection-fail-over;,
> the driver supports failover when ip addresses and ports of host are comma
> separated, like this:
> jdbc:postgresql://my-db-host-slave-1:5432,my-db-host-master-1:5432/database?targetServerType=primary
> .
>
> But it's not convenient, because we use k8s for pg, and there may be more
> slaves added and master ip may be changed.
>
> I want to store all my hosts in DNS and to specify one hostname like this:
> jdbc:postgresql://my-db-host.local:5432/database?targetServerType=primary
>
> I have a dns record with 2 ip addresses:
>
> $ nslookup my-db-host.local
> Server: 192.168.1.1
> Address: 192.168.1.1#53
>
> Non-authoritative answer:
> Name: my-db-host-slave-1
> Address: 192.168.10.21
> Name: my-db-host-master-1
> Address: 192.168.11.25
>
> and I tried to specify it like this:
> jdbc:postgresql://my-db-host.local:5432/database?targetServerType=primary.
>
> But this way it only picks the first ip - slave and fails with org.postgresql.util.PSQLException:
> Could not find a server with specified targetServerType: primary
>
> Is there any workaround for using dns failover? May be some options in
> connection pools if driver does not support that?
>

Currently no.  It would be a useful addition however.

Dave


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-11-21 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 09:07 Pg jdbc DNS failover Nikolay Prokofiev <[email protected]>
2023-11-21 13:07 ` Dave Cramer <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox