node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Unix sockets support on windows

Open SvanteRichter opened this issue 1 year ago • 1 comments

Thanks for the library! Had an issue with what probably is an edge-case, using unix sockets on windows.

UNIX sockets are supported by postgresql on windows (I can start and connect to a database with psql without listenening on any IP), but i cannot connect with node-postgres.

If I try something like

const client = new pg.Client({
  database: 'postgres',
  user: 'surface',
  password: 'surface',
  host: postgresqlServer.socketDir
})

or

const client = new pg.Client('postgres://surface:surface@surface//postgres?host=' + postgresqlServer.socketDir)

I get

  Error: getaddrinfo ENOTFOUND C:\Users\surface\Downloads\db\socket
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'C:\\Users\\surface\\Downloads\\db\\socket'

But if I try with an actual psql.exe it works:

psql.exe -d 'postgres://surface:surface@surface/postgres?host=C:\Users\surface\Downloads\db\socket'

Had a similar issue with postgres.js so opened a issue there too: https://github.com/porsager/postgres/issues/737

SvanteRichter avatar Nov 23 '23 11:11 SvanteRichter

The URLs used in the two examples are different; is it deliberate?

  1. ..pg.Client('postgres://surface:surface@surface//postgres?...
  2. psql.exe -d 'postgres://surface:surface@surface/postgres?...

#1 has a double / before postgres

alxndrsn avatar Mar 17 '24 07:03 alxndrsn