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, 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');


const connectionString = process.env.RENDER_CONNECTION_STRING;

const client = new Client({

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

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

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


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.