Re: connecting to localhost -> ::1 client_addr ?

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Luca Ferrari <fluca1978(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: connecting to localhost -> ::1 client_addr ?
Date: 2023-05-05 08:38:50
Message-ID: CABUevEzAH2cic4PwsBmigm3G5urMrcv5rkHNXH0BEsXX5eBr-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, May 5, 2023 at 9:23 AM Luca Ferrari <fluca1978(at)gmail(dot)com> wrote:
>
> Hi all,
> this may be tribial, but I'm seeing connections from ::1 in
> pg_stat_activity, and I've never realiuzed that psql converts
> "localhost" in IPv6.
> Is there a way to "force" the hostname localhost to appear as IPv4 or
> am I missing something?
>
> I've tested it also with a Perl program, and specifying localhost is
> providing ::1 too. I suspect this is mainly due to the host name
> resolution, but I'm not sure.

This is something that's part of your resolver library on your machine.

You can for example edit /etc/hosts to remove ::1. Or you can edit
/etc/gai.conf and change the priority order to put ipv4 first, that
should work as well I believe. (Those are assuming you're on Linux).

Or of course, you can configure listen_addresses to only have ipv4 in
it -- but then ipv6 won't work for *any* connections, it won't just
change the priority.

//Magnus

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Evgeny Morozov 2023-05-05 09:12:01 Re: "PANIC: could not open critical system index 2662" - twice
Previous Message Andrew Gierth 2023-05-05 08:38:48 Re: "PANIC: could not open critical system index 2662" - twice