Re: Feature: Use DNS SRV records for connecting

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Feature: Use DNS SRV records for connecting
Date: 2026-05-12 21:05:45
Message-ID: CAN4CZFOjC2GA55t075OzWZYbRmTt6+bWrLA0=sM_tuQUW9A2_A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

Shouldn't srvhost be freed in freePGconn?

+ /*
+ * If srvhost is set, validate mutual exclusivity with host/hostaddr and
+ * then resolve _postgresql._tcp.<srvhost> SRV records, populating
+ * conn->pghost and conn->pgport from the sorted results. This must
+ * happen before the host-array allocation below.
+ */
+ if (conn->srvhost != NULL && conn->srvhost[0] != '\0')

Shouldn't this also cover port? The current behavior with it seems inconsistent.

> The resolved host list is sorted per RFC 2782 and injected into the
> existing multi-host machinery before connhost[] is built, so
> target_session_attrs, load_balance_hosts, and failover work on the
> expanded list without any changes to PQconnectPoll.

Doesn't RFC 2782 specifies a weighted random selection? The current
code seems to be deterministically sorted by weight.
RFC also says that weight=0 should be specially handled, it provides a
detailed algorithm about the random selection method.

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Jacob Champion 2026-05-12 20:48:03 Re: [PATCH] libpq: try all addresses for a host before moving to next on target_session_attrs mismatch