From 0545fb765176dc301ace67e0029f399221d642e3 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Fri, 19 Dec 2025 21:59:55 -0300 Subject: [PATCH] fix: try to fix stale database connections (again) --- app/WYGIWYH/settings.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/WYGIWYH/settings.py b/app/WYGIWYH/settings.py index 8461121..fe99dca 100644 --- a/app/WYGIWYH/settings.py +++ b/app/WYGIWYH/settings.py @@ -143,6 +143,9 @@ WSGI_APPLICATION = "WYGIWYH.wsgi.application" # Database # https://docs.djangoproject.com/en/5.1/ref/settings/#databases +THREADS = int(os.getenv("GUNICORN_THREADS", 1)) +MAX_POOL_SIZE = THREADS + 1 + DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", @@ -151,8 +154,16 @@ DATABASES = { "PASSWORD": os.getenv("SQL_PASSWORD", "password"), "HOST": os.getenv("SQL_HOST", "localhost"), "PORT": os.getenv("SQL_PORT", "5432"), + "CONN_MAX_AGE": 0, + "CONN_HEALTH_CHECKS": True, "OPTIONS": { - "pool": True, + "pool": { + "min_size": 1, + "max_size": MAX_POOL_SIZE, + "timeout": 10, + "max_lifetime": 600, + "max_idle": 300, + }, }, } }