psycopg2.pool - Connections pooling - Psycopg 2.9.6 documentation
- Connections pooling
Creating new PostgreSQL connections can be an expensive operation. This module offers a few pure Python classes implementing simple connection pooling directly in the client application.
- class psycopg2.pool. AbstractConnectionPool ( minconn , maxconn , \*args , \*\*kwargs )
Base class implementing generic key-based pooling code.
New minconn connections are created automatically. The pool will support a maximum of about maxconn connections. *args and **kwargs are passed to the
The following methods are expected to be implemented by subclasses:
- getconn ( key = None )
Get a free connection from the pool.
The key parameter is optional: if used, the connection will be associated to the key and calling
getconn()with the same key again will return the same connection.
- putconn ( conn , key = None , close = False )
Put away a connection.
If close is
True, discard the connection from the pool. key should be used consistently with
The following classes are
subclasses ready to
- class psycopg2.pool. SimpleConnectionPool ( minconn , maxconn , * args , ** kwargs )
A connection pool that can’t be shared across different threads.
This pool class is useful only for single-threaded applications.