pool.end() not working
I ran the sample code you provided and the pool.end() does not seem to work. Code at: https://node-postgres.com/features/pooling
Code console.log("start async query"); const result = await pool.query("SELECT NOW()"); console.log("async query finished, now is: ", result.rows[0].now);
console.log("starting callback query"); pool.query('SELECT NOW()', (err, res) => { console.log("callback query finished, res is: ", res.rows[0].now); });
console.log("calling end"); await pool.end(); console.log("pool has drained");
Output Note: Missing the "callback query finished..." text. start async query async query finished, now is: 2023-12-21T01:54:14.233Z starting callback query calling end pool has drained
Should be as follows: start async query async query finished, now is: 2023-12-21T01:54:14.233Z starting callback query calling end callback query finished.... -- Missing pool has drained
When I comment out the following: await pool.end(); I get the expected behavior ("callback query finished..." is printed at the end).
Output start async query async query finished, now is: 2023-12-21T01:55:50.634Z starting callback query calling end pool has drained callback query finished, res is: 2023-12-21T01:55:50.666Z
There is no need to end the pool. Because it is connect and end itself.If you want to end then use client.