简体   繁体   中英

POSTGRESQL - Is it better to keep a db connection open from the moment a port is exposed or to open and close a connection for each request?

Title says it all.

Is it better to open a connection to my db when the app is initialized or should I connect and release the client for each query?

How do I use a connection pool correctly?

Opening and closing database connections repeatedly is a waste of time and CPU power. Therefpre, you should always use a connection pool.

When you use a connection pool, you don't open and xlose the connection, but take it from the pool and return it when you are done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM