psycopg2.pool – 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
connect()function.The following methods are expected to be implemented by subclasses:
-
getconn(key=None)¶ Get a free connection and assign it to key if not
None.
-
putconn(conn, key=None, close=False)¶ Put away a connection.
If close is
True, discard the connection from the pool.
-
closeall()¶ Close all the connections handled by the pool.
Note that all the connections are closed, including ones eventually in use by the application.
-
The following classes are AbstractConnectionPool subclasses ready to
be used.