Error: read ECONNRESET at TCP.onStreamRead

I’m having trouble connecting to our Postgres DB using the external connection string provided by Render. Below is my basic setup to connect taken from https://node-postgres.com/features/connecting, I keep running into this Error: read ECONNRESET at TCP.onStreamRead .

Connecting to the DB on my local machine works fine. I’m a beginner and most likely overlooking something. Any help will be appreciated.

const dotenv = require('dotenv');
const { Client } = require('pg');

dotenv.config();

const connectionString = process.env.RENDER_CONNECTION_STRING;

const client = new Client({
  connectionString
});

const queryDB = async () => {
  await client.connect();
  client.query('SELECT NOW()', (err, res) => {
    console.log(err, res);
    client.end();
  });
};

(async () => {
  try {
    await queryDB();
  } catch (error) {
    console.error(error);
  }
})();

Solved this by adding ssl=true to the connection URI supplied by Render

2 Likes

Oh my god thank you!

In my case I was not able to run Knex migrations connecting to the Render postgres database. The same connection settings were working in pgadmin and I could not see what the difference was.

The error message here could be more informative.

Thanks again.

1 Like

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