class PG::Connection

def resolve_hosts(iopts)

This requires PostgreSQL-10+, so no DNS resolving is done on earlier versions.
Multiple comma-separated values are generated, if the hostname resolves to both IPv4 and IPv6 addresses.
Resolve DNS in Ruby to avoid blocking state while connecting.
def resolve_hosts(iopts)
= iopts[:host].split(",", -1)
= iopts[:port].split(",", -1)
= [nil] if iports.size == 0
= iports * ihosts.size if iports.size == 1
G::ConnectionBad, "could not match #{iports.size} port numbers to #{ihosts.size} hosts" if iports.size != ihosts.size
 ihosts.each_with_index.flat_map do |mhost, idx|
 host_is_named_pipe?(mhost)
ber.respond_to?(:scheduler) &&
ber.scheduler &&
BY_VERSION < '3.1.'
e a second thread to avoid blocking of the scheduler.
CPSocket.gethostbyname` isn't fiber aware before ruby-3.1.
addrs = Thread.new{ Addrinfo.getaddrinfo(mhost, nil, nil, :STREAM).map(&:ip_address) rescue [''] }.value
addrs = Addrinfo.getaddrinfo(mhost, nil, nil, :STREAM).map(&:ip_address) rescue ['']
hostname to resolve (UnixSocket)
ddrs = [nil]
drs.map { |hostaddr| [hostaddr, mhost, iports[idx]] }
erge(
dr: dests.map{|d| d[0] }.join(","),
dests.map{|d| d[1] }.join(","),
dests.map{|d| d[2] }.join(","))