node-postgres
node-postgres copied to clipboard
Node v17 ECONNREFUSED
Description
On node v16.13.0, connecting to the database works as expected. I decided to try out the changes in v17.0.1 and I can't connect to the db anymore.
Test script:
import pg from 'pg';
export const pool = new pg.Pool({
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASS,
database: 'kb'
});
console.log(process.version);
pool.query(`SELECT NOW()`).then(({ rows }) => console.log(rows[0]));
Output (both versions)
pg>node test
v16.13.0
{ now: 2021-10-29T18:14:27.011Z }
pg>node test
v17.0.1
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
Error: connect ECONNREFUSED ::1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
}
Node.js v17.0.1
Environment
Windows 10, running postgres from WSL 2
What does your postgresql.conf
file say for listen_addresses
?
commented out, unchanged from install
@KhafraDev Try changing it to listen_addresses = '127.0.0.1,::1'
and see if that works?
I'm having the same issue with listen_addresses = '*'
and running on docker for mac. I assume https://github.com/docker/for-mac/issues/1432 could be the issue here.
@marcbachmann is your code running in a container and your DB running in another?
Sorry, I'm not sure what the issue was anymore. I was able to upgrade later and everything is running on node 18. Usually we have node outside docker, directly on the mac host, and then postgres within docker. Maybe I posted the comment above when I was trying to run it within our CI or on macos, therefore completely in docker. I can report back here in case it's still failing as I'll upgrade to node 18 within the next 2 weeks.