我正在使用 pg-promise
(以及底层的 pg-pool 库)。
当我拔掉我的 pg 数据库的插头简短(中断 TCP 连接),我收到 connect ETIMEDOUT
错误(预期),但是池需要很长时间才能恢复- 建立连接。大约 10 分钟。
这是我如何使用 pg-promise
的片段:
const pgp = pgPromise({
error(err, e) {
if (e.query) {
// Do stuff
}
},
});
...
const pgpArgs = {
host,
port,
database,
user,
password,
max,
idleTimeoutMillis: 5000,
};
const db = pgp(pgpArgs);
我看到了作者的 this 潜在答案,但我不想为了重新建立池而终止整个过程。
除了重启 nodejs 进程,有没有办法强制池中的客户端重新连接?
提前致谢。