Disconnect from DB

I’m running my server from file (node) and after a few minutes, each and every time, I receive the following error:

node:events:505
throw er; // Unhandled ‘error’ event
^

Error: Connection terminated unexpectedly
at Connection. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:132:73)
at Object.onceWrapper (node:events:641:28)
at Connection.emit (node:events:527:28)
at Socket. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\connection.js:63:12)
at Socket.emit (node:events:539:35)
at TCP. (node:net:709:12)
Emitted ‘error’ event on Client instance at:
at Client._handleErrorEvent (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:341:10)
at Connection. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:150:16)
at Object.onceWrapper (node:events:641:28)
[… lines matching original stack trace …]
at TCP. (node:net:709:12)

The code I’m using to connect is as follows (v basic):
const { Client } = require(‘pg’);
const connectionString = process.env.CONNECTION_STRING;

const client = new Client({
connectionString,
});

client.connect();

module.exports = client;

Does anyone know why the connection keeps dropping? Thanks

1 Like

I’m experiencing the exact same thing. I also have nearly an identical setup. Were you able to figure it out? This started happening maybe 2 to 3 weeks ago for me. Only happens locally.

This issue is still plaguing me. I know it’s not my code because even my postgres db viewer loses connection every few minutes as well. It’s like the DB can’t keep a connection outside of the private network. Is there anyone at render who can help?

Still happening. Seems like it is something wrong with the db from render.

Still happening. Render could you please look into or help? The DB instance is a starter & a pro.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.