我有一个在 Heroku 上运行的 NodeJS 应用程序,带有 Heroku Postgres 数据库。
现在 (pg@^7.18.2
& knex@^0.21.14
),当我运行 heroku run knex migrate:latest -a my-awesome-app
时,我收到以下错误:
KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at Client_PG.acquireConnection (/app/node_modules/knex/lib/client.js:348:26)
at async listCompleted (/app/node_modules/knex/lib/migrate/migration-list-resolver.js:12:3)
at async Promise.all (index 1)
at async Migrator.latest (/app/node_modules/knex/lib/migrate/Migrator.js:64:29)
at async Command.<anonymous> (/app/node_modules/knex/bin/cli.js:172:32)
我在 Google 上搜索并发现很多人说解决方案是更新到 pg@^8
,所以我这样做了(将 pg
和 knex
都升级到了最新的稳定版本)但我现在得到了一个不同的错误。这次的错误是:
heroku run knex migrate Error: self signed certificate
所以我在 Google 上搜索了新错误,人们说解决方案是将 ssl: { rejectUnauthorized: false },
添加到 Knex 配置对象,但我也这样做了,但仍然出现“自签名证书”错误。
我什至尝试了 suggestions here,但仍然没有运气,错误仍然存在。
有些答案建议我应该返回到版本 pg@^7
以克服证书错误,但在我的情况下,我只是返回获取连接错误的超时。
我被两个错误困住了,但似乎没有任何效果。如果您能提供一些帮助或建议,我将不胜感激。
答案 0 :(得分:0)
尝试检查您的节点版本,可能您使用的是新版本的节点 js 并且 knex 与节点 v14 存在一些问题。尝试将其降级到 v12。
答案 1 :(得分:0)
如果有人遇到此问题,请将其发布给后代。我在 Heroku postgres 中使用的在其他任何地方都没有看到的语法是:
// knexfile.js
module.exports = {
// dev environment here...
production: {
client: "pg",
connection: {
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false },
},
migrations: {
directory: __dirname + "/db/migrations",
},
seeds: {
directory: __dirname + "/db/seeds",
},
},
};
my medium article which goes through the various docs and links