[POC] Implement async DNS with getaddrinfo_a

From: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Evgeny Kuzin <evgeny(dot)kuzin(at)outlook(dot)com>
Subject: [POC] Implement async DNS with getaddrinfo_a
Date: 2026-07-07 21:18:35
Message-ID: CAOYmi+mBW0h9F5ZKkaUPuK=6T080Qs49+XCsv6Cee=g_zmitbw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

With several recent discussions focusing on DNS features [1, 2], I
coded up an experiment during PGConf.dev to see if we could get simple
async DNS support going. I cleaned it up a bit today, and it looks
like all the architectural bones are there; we'd just need to do the
(hard) work of deciding what OSes to support and what the behavior
should be in the corner cases.

This is just a proof-of-concept, with multiple TODOs. It hacks up the
existing altsock support in libpq to handle connection establishment,
using glibc's getaddrinfo_a as a sample (the BSDs have their own
distinct APIs, I think). getaddrinfo_a is fundamentally a
background-thread architecture, so this implementation might not be
something we want to pursue in the end. But it does pass
libpq/t/004_load_balance_dns, which is a decent start.

I don't plan to make DNS a primary focus of mine for PG20, but anyone
who's interested is welcome to take this and play with it. Note that
our code coverage for DNS behavior is currently very poor: the
overwhelming majority of our tests use Unix sockets and/or loopback IP
addresses.

Thanks,
--Jacob

[1] https://postgr.es/m/8398C22D-429A-4980-9028-4F941F2B7483%40yandex-team.ru
[2] https://postgr.es/m/AM9PR09MB49008B02CDF003054D5D4E00977DA%40AM9PR09MB4900.eurprd09.prod.outlook.com

Attachment Content-Type Size
0001-WIP-Switch-to-getaddrinfo_a-where-available.patch application/octet-stream 2.2 KB
0002-libpq-Break-address-resolution-into-its-own-helper.patch application/octet-stream 9.0 KB
0003-WIP-libpq-Implement-async-DNS-with-green-tests.patch application/octet-stream 18.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-07-07 21:19:38 Re: hashjoins vs. Bloom filters (yet again)
Previous Message Heikki Linnakangas 2026-07-07 21:12:36 Re: Restructured Shared Buffer Hash Table