Node-postgres: When should I use Pool.end();

Created on 9 Jun 2018  Â·  2Comments  Â·  Source: brianc/node-postgres

I'm creating a project using the node-postgress documentation:
https://node-postgres.com/features/connecting

in the documentation shows an example of a query using pool where at the end of the request it terminates the connection with the pool.end ();

I followed the same example and it worked, but when I try to do a second query this error occurs:

Cannot use a pool after calling end on the pool Error: Cannot use a pool after calling end on the pool at Pool.connect (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\pg-pool\index.js:141:19) at Pool.query (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\pg-pool\index.js:251:10) at StudentController.getAll (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\controllers\StudentController.js:11:16) at Layer.handle [as handle_request] (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\layer.js:95:5) at next (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\layer.js:95:5) at c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:281:22 at Function.process_params (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:335:12) at next (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:275:10)

question

Most helpful comment

In a long running program you don’t need to call ‘pool.end()’ unless you’re going to dynamically create and gracefully shutdown a pool. In most cases you can ignore it entirely as exiting the node process will close the sockets for the pool.

All 2 comments

In a long running program you don’t need to call ‘pool.end()’ unless you’re going to dynamically create and gracefully shutdown a pool. In most cases you can ignore it entirely as exiting the node process will close the sockets for the pool.

in the documentation shows an example of a query using pool where at the end of the request it terminates the connection with the pool.end ();

The documentation shows an example script you can run standalone; there’s no request involved. pool.end() should be called when you don’t intend to use the pool anymore, so in a web server, you would call it when shutting down (or not at all).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lucasmrl picture lucasmrl  Â·  3Comments

tonylukasavage picture tonylukasavage  Â·  4Comments

dipakdas99 picture dipakdas99  Â·  3Comments

chovy picture chovy  Â·  3Comments

frmoded picture frmoded  Â·  3Comments