Please explain me what is connection pool in Postgres and MongoDB database.
A connection pool is a software component that acts as a kind of proxy or multiplexer between the application code and the database.
Instead of opening a database connection in your code, you request a connection from the pool, and you return the connection to the pool rather than closing it. The connection pool maintains a number of persistent database connections that get reused.
Connection pools are usually built into the application server or database driver code, but they can be standalone programs like pgBouncer.
The advantages of connection pools are twofold:
It avoids waste of database processing power by opening and closing database connections all the time, which can be a quite expensive operation.
It provides an artificial bottleneck to keep the database from being overloaded by too many concurrent requests.
Often, connection pools will keep processes/threads suspended in a queue if no database connection is available at the moment rather than making the requests fail.