【问题标题】:heroku run knex migrate:latest errors: Knex: Timeout acquiring a connection and knex migrate Error: self signed certificateheroku 运行 knex 迁移:最新错误:Knex:超时获取连接和 knex 迁移错误:自签名证书
【发布时间】:2021-05-11 00:30:02
【问题描述】:

我有一个在 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

所以我用谷歌搜索了新的错误,人们说解决方案是将ssl: { rejectUnauthorized: false }, 添加到 Knex 配置对象,但我也这样做了,但我仍然收到“自签名证书”错误。

我什至尝试了suggestions here,但仍然没有运气,错误仍然存​​在。

一些答案​​建议我应该回到版本 pg@^7 来克服证书错误,但就我而言,我只是回到超时获取连接错误。

我被困在两个错误之间,似乎没有任何效果。

【问题讨论】:

  • 你有用于连接的 cert/key/ca 吗?
  • 不,我需要一个吗?如果是,我该如何获得。
  • 不确定heroku .. 可能不能according to this。虽然你配置什么来从你的 heroku 应用程序连接? (不使用knex cli)
  • 你能分享你的knexfile吗?我想知道您是否将 ssl 块放在了错误的位置,或者是否还有其他特定于 Heroku 的事情发生。

标签: node.js postgresql heroku knex.js


【解决方案1】:

如果有人遇到此问题,请将其发布以供后代使用。我在其他任何地方都没有看到的 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

【讨论】:

    【解决方案2】:

    尝试检查您的节点版本,可能您正在使用新版本的节点 js,并且 knex 在节点 v14 上遇到了一些问题。尝试将其降级到 v12。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-30
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      • 2020-01-17
      相关资源
      最近更新 更多