0

Attempts to connect using pgAdmin 4 are successful.

Attempts to connect using NPM package PG are refused.

ConnectErr connect EHOSTUNREACH fe80::xx:xxxx:xxxx:xxxx:5432 - Local (fe80::xxxx:xxx:xxxx:xxx%en5:54602)

Both attempts use the same client settings, addressing the PG server by its local domain name:

host: machineName.local
port: 5432
user: "userName"
password: "password"
database: "postgres"

The problem can be resolved by changing the hostname to the host's LAN IPv4. host:

host: 192.168.x.x

Wondering if the problem is that under the NPM package, the domain name gets translated to IPv6 and therefore gets refused?

I was under the impression that pg_hba.conf is configured to handle both IPv4 and IPv6:

# TYPE   DATABASE      USER   ADDRESS       METHOD
# "local" is for Unix domain socket connections only
local    all           all                  peer
# IPv4 local connections:
host     all           all    0.0.0.0/0     md5
# IPv6 local connections:
host     all           all    ::0/0         md5
# Allow replication connections from localhost, by a user with the replication privilege.
local   replication    all                  md5
host    replication    all    127.0.0.1/32  md5
host    replication    all    ::1/128       md5
WhatsYourFunction
  • 621
  • 1
  • 9
  • 25
  • 1) What is [listen_addresses](https://www.postgresql.org/docs/current/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS) set to in `postgresql.conf`? 2) Are connecting from the same machine the server is on? 3) If not is there a firewall blocking connections? – Adrian Klaver Apr 09 '23 at 16:21
  • 1) listen_addresses = '*' 2) Client and pg Server are different machines on the same LAN. Note: the tests (using pgAdmin4 and node-postgres) are being conducted from the same client machine. 3) No firewall. Note: The client connects successfully from pgAdmin4 always. But it fails when using node-postgres + the local domain "machineName.local". Switching to a local IPv4 fixes the problem, but I'm trying to figure out why. – WhatsYourFunction Apr 09 '23 at 16:59
  • I'm guessing it some sort of name resolution issue. Further betting that the error: `EHOSTUNREACH fe80::xx:xxxx:xxxx:xxxx:5432 - Local (fe80::xxxx:xxx:xxxx:xxx%en5:54602)` is the key. Though I'm not actually sure what that is saying? At a glance would guess that `fe80::xx:xxxx:xxxx:xxxx:5432` is not mapping to `fe80::xxxx:xxx:xxxx:xxx%en5:54602`. – Adrian Klaver Apr 09 '23 at 17:17
  • I was wondering about that myself. What's with port 54602? (assuming that's what en5:54602 means?) I don't believe that's in my code anywhere, unless I spilled a drink on the keyboard and pounded the wrong port # – WhatsYourFunction Apr 09 '23 at 18:26
  • Rough description: `port = 5432` designates the port the parent process(`postmaster`) listens on. Postgres is process based so it cranks up a new process for each connection. Each of those processes gets their own port, so for example I show `postgres: postgres test ::1(56246) idle` for a recent connection to database test. That is where I bet the `54602` is coming from. What I don't know is `...%en5...` means? What OS and version are you using? – Adrian Klaver Apr 09 '23 at 20:35
  • MacOS is Ventura 13.2. Re "en5" I was assuming it was one of the may "en" entries that come up under ifconfig. Though I checked ifconfig, and there's en0 - e4, en9, and en10, but no en5. So now I'm not so sure. – WhatsYourFunction Apr 09 '23 at 23:14

0 Answers0