Thread

  1. [POC] Implement async DNS with getaddrinfo_a

    Jacob Champion <jacob.champion@enterprisedb.com> — 2026-07-07T21:18:35Z

    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