Pg jdbc DNS failover

Поиск
Список
Период
Сортировка
От Nikolay Prokofiev
Тема Pg jdbc DNS failover
Дата
Msg-id CABwh0FDqOiHh2Y_Qqq8iTOLoKDwxZrgia97wZnWk0n1M_6cJvg@mail.gmail.com
обсуждение исходный текст
Ответы Re: Pg jdbc DNS failover
Список pgsql-jdbc

Hi. According to pgjdbc documantation, 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?

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Mapping of timestamptz to TIMESTAMP vs. TIMESTAMP_WITH_TIMEZONE
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Pg jdbc DNS failover