0
我有以下疑问:如何检查pg池是否活动/有效?
问题1:在下面的代码,调用游泳池的任何功能之前,我该如何确保游泳池是活动?
const { Pool } = require('pg');
var pool = new Pool(); //global variable, used by multiple modules
function f1(){
/*
Check here if pool is active or not. If active, then execute following
code
*/
pool.connect(...)
}
如果我不签,则可能如果池是不活动状态(可能已经被其他模块结束)会出现以下错误。
Error: Cannot use a pool after calling end on the pool
查询2:如果我不结束游泳池会发生什么?
至于第一个查询,我想知道是否有任何可能性,池可能结束/自行关闭(如果'pool.end()'还没有已被使用)。根据[线程](https://github.com/brianc/node-postgres/issues/1477)中的讨论,似乎答案是“否”。 –
不确定游泳池,但其中的连接将在指定的超时后关闭。 –
对于数据库连接,它明确写在文档中,并且适当的事件监听器也在那里。我只怀疑pg池。 –