node.jstypescriptpostgresqlheroku

Heroku postgresql queries not working on Heroku, but work locally


When running locally and connecting to Heroku with the same DATABASE_URL, I'm able to connect and query the db perfectly fine.

When the same code is running on Heroku -- the query never returns and will eventually time out.

DB Code:

const connectionString = process.env.DATABASE_URL;
const pool = new Pool(
    {
        connectionString: connectionString,
        ssl: true
    }
);

public async query(text: any, params: any): Promise<any> {
    return pool.query(text, params);
}

This works as expected when I run on localhost and attach to the Heroku Postgres add-on (Hobby tier), but when deployed to Heroku it no longer works. The DATABASE_URL is loaded correctly though.


Solution

  • Weird one, but if anyone runs into this problem here was our solution:

    We used the pg package and were running version ^7.12.1, which allowed us to connect and query the Heroku hosted database locally, but not when the server was deployed on Heroku.

    The fix was updating the pg package, which we are now running version ^8.5.1.