Postgresql tries to connect to fe80::1, permission denied

connectionspostgresql

I upgraded a couple of days ago to IPv6 on my local test machine and since then I've been experiencing some issue with connecting to my local PostgreSQL server.
I set the host to 'localhost', which worked fine using IPv4. While using IPv6, there is a 1:150 chance that the connection fails (here is a testcase for all unix systems, and here is another one for all other systems (requires psycopg2 and python3)).
As it turns out it is because the loopback interface (lo0) is configured like this:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 ::1 prefixlen 128 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1  # line 5
    nd6 options=1<PERFORMNUD>

Line 5 is especially interesting. It says use IP address fe80::1 for connections (and which is actually used about every 150th time).
Is it safe to allow all connections (without password) from fe80::1 or did my PC just happen to be number one on the local network? Can my IP change when I'm on another network (I used to 10.0.0.1 on IPv4 but that changed occasionally depending on where I am).
If other computers can also use fe80::1, how can I prevent postgresql from connecting to my server using that address? If I change the host to "::1", will postgresql even work on networks (routers) that don't support IPv6 / haven't IPv6 enabled? Or do I need to use IPv4 (i.e. 127.0.0.1) for 100% stable connection?

Additional tags: IPv6, loopback
(Sorry I can't create tags on my own, yet).

Best Answer

So this is almost certainly a bad configuration in ip address resolution. As you mention, you have a line resolving localhost to your external ipv6 address. Yes, this should be removed, or changed from fe80::1 to ::1