Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5MjX-00DCNI-Sg for pgsql-jdbc@arkaria.postgresql.org; Tue, 21 Nov 2023 09:07:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r5MjV-00FT85-CG for pgsql-jdbc@arkaria.postgresql.org; Tue, 21 Nov 2023 09:07:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5MjV-00FT7b-08 for pgsql-jdbc@lists.postgresql.org; Tue, 21 Nov 2023 09:07:49 +0000 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r5MjO-006cG0-If for pgsql-jdbc@lists.postgresql.org; Tue, 21 Nov 2023 09:07:47 +0000 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-d9bf9122c1aso659028276.1 for ; Tue, 21 Nov 2023 01:07:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700557661; x=1701162461; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=qQzpW9CR2b/gr+HbmS/8BLZGYgTejwIA59h47asfk1k=; b=R7ML7gLHLNGsy4RA7FFVeUPxuWSDbvSyqlPw/wRgMphw4/EzuowpdjYmc7nHpS0BMT BZENqysNB0D6iI/DY3a6hApB5R3RdXMCnJAO1ihCzL7iM1oxLCxxKJFqzycTiEocQqXa EePzGPiPmF6SYqpjvA5yLaSrRv+CAQRVyn64kI+vtKgBT0gdmV+xSmwwsjBFIWRMT8dX GAV1hp2FLBd4J5DFfly+Yfhs4+hQMAJX+N1Jukc1Streru61gfi918bD/T7X1jUZMHT0 wTeJTauOhvqvTUxUbd056oSWP2wGt5fTHd3cQLjmkGw50P5t7wXWzP4BBN/eM4Iwa9EN 2WLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700557661; x=1701162461; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qQzpW9CR2b/gr+HbmS/8BLZGYgTejwIA59h47asfk1k=; b=uklupzSrXI717b3BxVM7nlBJYiEl7rUtDiBliRrEQPQoRNyerKQqPXO97/GVcGQh3b uY6SLuwpPZmwTZbJa79QZYUEGADTKJH6mU6oZp0GZ0+ehN6sjUzsPQb2NMF+C5Zoig3I s2m4cwewEJT/ZPBR75Ic0aUDMc/cyA+D783LsYL9dQvxAvLGphiJFRWZ8X3Ykc9SUKoI ytJZXTl8DlBEbpeQx47ObGjlMJjV2kEUZUaYjTluIRmXcFmmHICfVOoyxNemoNv6WWxl XVDVIy+YkJ831dFg4C22i9mxW4EvNDI0xSNTZnE6HUoTT6AC/zJqndnsAfmN0VQLdopq eqVw== X-Gm-Message-State: AOJu0Yyg3yL+JHOOV8JXhfUWSJuj9YD3jo29iEPJghBuE45W8q24OREa sPKMDP9frysiWZN8wzNYEZd/2P8uMR4lVqFAQQbvWkQN X-Google-Smtp-Source: AGHT+IEVnajqO2cuaIrNq2/a5W9Uiz23kEWBih3gWAnhppMDHhuxVdeO7zM4dNeiT7QPlEero/Uq1k2FTwWOJe4GxAA= X-Received: by 2002:a25:bc4c:0:b0:daf:f648:8bfa with SMTP id d12-20020a25bc4c000000b00daff6488bfamr5298077ybk.2.1700557661434; Tue, 21 Nov 2023 01:07:41 -0800 (PST) MIME-Version: 1.0 From: Nikolay Prokofiev Date: Tue, 21 Nov 2023 12:07:30 +0300 Message-ID: Subject: Pg jdbc DNS failover To: pgsql-jdbc@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000005476c6060aa5efcd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005476c6060aa5efcd Content-Type: text/plain; charset="UTF-8" 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? --0000000000005476c6060aa5efcd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi. According to=C2=A0pgjdbc = documantation, the driver supports failover when ip addresses and ports= of host are comma separated, like this:=C2=A0jdbc:postgresql://my-db-host-slave-1:= 5432,my-db-host-master-1:5432/database?targetServerType=3Dprimary.

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

I want to stor= e all my hosts in DNS and to specify one hostname like this:=C2=A0jdbc:postgresql:/= /my-db-host.local:5432/database?targetServerType=3Dprimary

I= have a dns record with 2 ip addresses:

$ nsloo=
kup my-db-host.local
Server: 192.168.1.1=
=20
Address: 192.168.1.1#53=20

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

and I tried to specify it like this:=C2=A0jdbc:postgresql://my-db= -host.local:5432/database?targetServerType=3Dprimary.

But th= is way it only picks the first ip - slave and fails with=C2=A0org.postgresql.util= .PSQLException: Could not find a server with specified targetServerType: pr= imary

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

--0000000000005476c6060aa5efcd--