我正在尝试使用PostgreSQL连接到Knex.js数据库,但是我无法获得连接。我看到的唯一例外是:
Error KnexTimeoutError: Knex: Timeout获取连接。游泳池可能满了。你错过了一个.transacting电话吗?
我构建了这个简单的测试脚本,以确保它不是我们程序的一部分:
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获得更多信息的方法,我会非常感激的。
发布于 2020-10-21 05:31:37
我把这个问题追溯到我们正在使用的“pg”软件包的verion。正在使用7.18,当我升级到最新版本(8.4)时,它开始连接。不知道为什么7.x版本不起作用。
https://stackoverflow.com/questions/64409791
复制相似问题