Support connection pooling kwargs
Hi 👋
We would like to migrate to dj-database-url (more precisely environs[django]), but we are currently leveraging the psycopg v3 database connection pool functionality (new in django v5.1).
Is there a generic mechanic in place to migrate the following code to the dj-database-url parse constructor?
"OPTIONS": {
# TODO replace with ?sslmode=require in DATABASE_URL
"sslmode": env("DJANGO_DB_SSLMODE", "require"),
# https://www.psycopg.org/psycopg3/docs/api/pool.html#psycopg_pool.ConnectionPool
"pool": {
"min_size": env.int("DJANGO_DB_POOL_MIN_SIZE", 4),
"max_size": env.int("DJANGO_DB_POOL_MAX_SIZE", 32),
"max_lifetime": env.int("CONN_MAX_AGE", 60 * 60),
"max_idle": env.int("CONN_MAX_IDLE", 10 * 60),
},
},
Relatedly, somewhat, do you know if it's possible to include ["OPTIONS"]["pool"] in a DB URL as querystring param?
@mattseymour would you accept a PR that follows double underscore syntax like ?pool__min_size=42&pool__max_idle=42?
if the conn_max_age kwarg is passed and not 0, django init will crash ref https://github.com/django/django/pull/17914#discussion_r1914650364. do you want to catch that beforehand or do you find django's error message verbose enough? I just opened a PR to clarify this behaviour in docs: https://github.com/django/django/pull/19442
I have a different reason for the same request as the issue title. We use this package and deploy to Heroku that manages the DATABASE_URL for you, so I can't use the querystring param to add pool=True. I was only looking at using True/False for now for testing this new Django feature, so haven't thought as far as OP about the dictionary option.
+1 to include a pool option.
Okay let me look into this, but likewise happy to accept a PR if someone would like to pick it up. It shouldn't be too hard to implement.