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

Error: Connection terminated unexpectedly

Open Gray486 opened this issue 4 years ago • 3 comments

I get this error after running the following code after a few minutes. I tried to figure this out but I suck. It was working fine for a while but I have no idea what I did to break it.

const client = new Client({
    user: "gray486",
    host: "db.bit.io",
    database: "gray486/website",
    password: process.env['PASSWORD'],
    port: 5432,
    ssl: true,
});
client.connect();

client.query('SELECT * FROM saves limit 10;', (err, res) => {
    console.table(res.rows);
});

These are the errors I get:

Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/node_modules/pg/lib/client.js:272:71)
    at Object.onceWrapper (node:events:627:28)
    at Connection.emit (node:events:513:28)
    at TLSSocket.<anonymous> (/node_modules/pg/lib/connection.js:102:10)
    at TLSSocket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on Client instance at:
    at connectedErrorHandler (/node_modules/pg/lib/client.js:221:10)
    at Connection.<anonymous> (/node_modules/pg/lib/client.js:289:9)
    at Object.onceWrapper (node:events:627:28)
    [... lines matching original stack trace ...]
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Gray486 avatar Aug 09 '22 11:08 Gray486

You're having some kind of network partition or connectivity issue between your node process and your database. This isn't an issue w/ this library directly...something going on in your environment causing that error.

brianc avatar Aug 09 '22 14:08 brianc

OK thank you

Gray486 avatar Aug 09 '22 15:08 Gray486

Check your connection pool

timakhalaya avatar Mar 03 '24 20:03 timakhalaya