I've recently upgraded to Django 5.1 and configured the database pooling option with the following settings:
DATABASES["default"]["OPTIONS"] = {
"pool": {"min_size": 2, "max_size": 4, "timeout": 10}
}
DATABASES["default"]["CONN_MAX_AGE"] = None
However, I encountered the following error: ImproperlyConfigured: Pooling doesn't support persistent connections.
I understand that removing CONN_MAX_AGE = None
will resolve this issue, but I would like to gain a deeper understanding of this limitation. Specifically, is the restriction on using persistent connections with pooling a constraint unique to Django's implementation, or does it extend to PostgreSQL
(or other databases) in general? Additionally, what are the underlying reasons for this incompatibility?
The Connection pooling option in Django 5.1 uses psycopg_pool.ConnectionPool to handle the pooling logic and Django doesn't implement the logic on it's own. Django simply returns the connection back to this pool after each request and leaves the handling of closing the connection to it since that's supposed to be handled by the pool.
The ConnectionPool
class has it's own options which you can configure by the dictionary you pass to the pool
option. If you want something similar to CONN_MAX_AGE
you can configure the max_lifetime
argument.