Knex.js 不会连接到 postgres

Knex.js won't connect to postgres

我正在尝试使用 Knex.js 连接到 PostgreSQL 数据库,但我就是无法建立连接。我看到的唯一例外是:

Error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

我构建了这个简单的测试脚本以确保它不是我们程序的一部分:

const knex = require("knex")({
    client: 'pg',
    connection: {
        host : 'localhost',
        port: 5432,
        database: 'postgres',
        user: 'postgres',
        password: 'password'
    },
    pool: {
        afterCreate: (conn, done) => {
            console.log("Pool created");
            done(false, conn);
        }
    },
    debug: true,
    acquireConnectionTimeout: 2000
});

console.log("A")

const a = knex.raw('select 1+1 as result').then(result => console.log("A Success", result)).catch(err => console.log("A Error", err));

console.log("B")

const b = knex.select("thing").from("testdata").then(data => console.log("B Success", data)).catch(err => console.log("B Error", err));

console.log("C")

const c = knex.transaction(trx => {
    trx.select("thing").from("testdata")
        .then(data => {
            console.log("C Success", data);
        })
        .catch(err => {
            console.log("C Error", err);
        });
})
    .catch(err => {
        console.log("C Error", err);
    });

console.log("waiting on query")
// Promise.all([a, b, c]).then(() => {
//     console.log("Destroying")
//     knex.destroy()
// })

产生以下输出

A
B
C
waiting on query
A Error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at Client_PG.acquireConnection (E:\DEV\work\niba-backend\node_modules\knex\lib\client.js:347:26)
    at runNextTicks (internal/process/task_queues.js:58:5)
    at listOnTimeout (internal/timers.js:520:9)
    at processTimers (internal/timers.js:494:7) {
  sql: 'select 1+1 as result',
  bindings: undefined
}
B Error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at Client_PG.acquireConnection (E:\DEV\work\niba-backend\node_modules\knex\lib\client.js:347:26) {
  sql: undefined,
  bindings: undefined
}
C Error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at Client_PG.acquireConnection (E:\DEV\work\niba-backend\node_modules\knex\lib\client.js:347:26)
    at async Transaction.acquireConnection (E:\DEV\work\niba-backend\node_modules\knex\lib\transaction.js:213:28)

它从不调用 afterCreate 方法。我已经使用适用于其他所有人的设置对我们的开发数据库进行了尝试,并在本地 运行 postgres 安装中尝试了我能想到的每种设置组合。我什至将它传递给了团队的另一名成员并且它运行良好,所以我的机器中出现了一些问题,但我不知道是什么阻止了它。我在 postgres 日志中没有看到任何连接尝试,而且我似乎无法获得任何更好的错误消息。

如果有人能提出我可以尝试的方法,或者从 Knex 获取更多信息的方法,我将不胜感激。

我将问题追溯到我们使用的 'pg' 包的版本。使用的是 7.18,当我升级到最新版本 (8.4) 时,它开始连接。不知道为什么 7.x 版本不起作用。