简体   繁体   English

Heroku postgresql 查询不适用于 Heroku,但在本地工作

[英]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.在本地运行并使用相同的DATABASE_URL连接到 Heroku 时,我可以完美地连接和查询数据库。

When the same code is running on Heroku -- the query never returns and will eventually time out.当在 Heroku 上运行相同的代码时,查询永远不会返回,最终会超时。

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.当我在 localhost 上运行并附加到 Heroku Postgres 附加组件(爱好层)时,这按预期工作,但是当部署到 Heroku 时它不再工作。 The DATABASE_URL is loaded correctly though. DATABASE_URL已正确加载。

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.我们使用pg package 并运行版本^7.12.1 ,这允许我们在本地连接和查询 Heroku 托管数据库,但在服务器部署在 Z1A79417461C9ADBE88F8B93E 上时不能。

The fix was updating the pg package, which we are now running version ^8.5.1 .修复是更新pg package,我们现在正在运行版本^8.5.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM