From 77a3edf63aa84deacbc8a0e1addeb2f6d3eeeb98 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 28 May 2026 19:31:50 -0500 Subject: [PATCH] perf/fix: migrate DB driver to psycopg3, fix pool settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Switch engine to postgresql_psycopg3 (PR had wrong engine name, and we're migrating from psycopg2 to psycopg3 as part of this work) - Set CONN_MAX_AGE=0 (required by geventpool; PR had None) - Reduce MAX_CONNS 20→8, REUSE_CONNS 10→3 to avoid exhausting pg max_connections across 4 uWSGI workers + Celery - Add pool=False to explicitly disable Django's native psycopg3 pool --- dispatcharr/settings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dispatcharr/settings.py b/dispatcharr/settings.py index 1b103ccf..6a6856db 100644 --- a/dispatcharr/settings.py +++ b/dispatcharr/settings.py @@ -111,7 +111,7 @@ XC_PROFILE_REFRESH_DELAY = float(os.environ.get('XC_PROFILE_REFRESH_DELAY', '2.5 # Database optimization settings DATABASE_STATEMENT_TIMEOUT = 300 # Seconds before timing out long-running queries -DATABASE_CONN_MAX_AGE = None # Managed by django-db-geventpool; None = persistent pool connections +DATABASE_CONN_MAX_AGE = 0 # geventpool intercepts close(); pool handles reuse # Disable atomic requests for performance-sensitive views ATOMIC_REQUESTS = False @@ -221,7 +221,7 @@ if os.getenv("DB_ENGINE", None) == "sqlite": else: DATABASES = { "default": { - "ENGINE": "django_db_geventpool.backends.postgresql", + "ENGINE": "django_db_geventpool.backends.postgresql_psycopg3", "NAME": os.environ.get("POSTGRES_DB", "dispatcharr"), "USER": os.environ.get("POSTGRES_USER", "dispatch"), "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "secret"), @@ -229,8 +229,9 @@ else: "PORT": int(os.environ.get("POSTGRES_PORT", 5432)), "CONN_MAX_AGE": DATABASE_CONN_MAX_AGE, "OPTIONS": { - "MAX_CONNS": 20, # Per-worker pool size; 4 workers × 20 = 80 total < pg max_connections=100 - "REUSE_CONNS": 10, # Connections to keep warm between requests + "MAX_CONNS": 8, # Per-worker pool size; 4 workers × 8 = 32 total < pg max_connections=100 + "REUSE_CONNS": 3, # Connections to keep warm between requests + "pool": False, # Disable Django's native psycopg3 pool; geventpool manages connections }, } }