Re: Psql wants to use IP6 when connecting to self using tcp... - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: Psql wants to use IP6 when connecting to self using tcp...
Date
Msg-id 20210624154227.GA22620@hjp.at
Whole thread Raw
In response to Re: Psql wants to use IP6 when connecting to self using tcp...  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Psql wants to use IP6 when connecting to self using tcp...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 2021-06-23 20:33:33 -0400, Tom Lane wrote:
> Jerry LeVan <jerry.levan@gmail.com> writes:
> > bigbox has a freshly installed Fedora 34 system and it runs postgresql 13.3
>
> > the following are being run ON bigbox
>
> > nslookup bigbox  returns the correct ipv4 address
> > nslookup bigbox.skynet returns the correct ipv4 address
>
> > psql -h bigbox.skynet allows me to connect to the database
> > psql -h bigbox  fails because the ipv6 address is returned and there is no hba entry..
>
> It's quite odd that nslookup isn't agreeing with glibc's name
> resolution code.

AFAIK nslookup uses only DNS. Glibc uses all methods in nsswitch.conf.
Typically that also includes "files", and at least on Debian/Ubuntu that
has higher priority than "dns", which is why I advised the OP to
check /etc/hosts. As Alan noted, mdns4_minimal is also often there and
might return spurious results.

> I suspect that the problem lies with systemd,

This is the next one, yes. On my Ubuntu laptop, the hosts line reads:

hosts:
    files
    mdns4_minimal [NOTFOUND=return]
    resolve [!UNAVAIL=return]
    dns
    myhostname
    mymachines

(wrapped for readability)

So glibc first looks in /etc/hosts, then does an MDNS (Avahi) lookup,
then asks systemd-resolved, and only then gets around to do a
traditional DNS lookup.

(And systemd-resolved does do some magic for the local hostname, so that
might indeed be the problem)

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: OSX: migrating Postgres db from one Mac to another
Next
From: Tom Lane
Date:
Subject: Re: Psql wants to use IP6 when connecting to self using tcp...