Justin K
Justin K

Reputation: 11

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?

Upvotes: 0

Views: 503

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247235

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.

Upvotes: 1

Related Questions