Skip to content

Commit

Permalink
fix(db): database connection errors (#56)
Browse files Browse the repository at this point in the history
This is an attempted fix for the databases connections errors at high load. Specifically, the error,  `OperationalError: could not connect to server: Connection refused`. The fix includes the following changes:
1. Performing health checks on existing connections on each request.
2. Disable Atomic requests on every view.
3. Increasing the maximum duration of a db connection to 3 minutes. (This is done using an environment variable on the deployment platforms).

This is a temporary fix and might have a minimal impact or not solve the problem. A proper fix might be implementing proper database connection pooling using tools such as [pgbouncer](https://www.pgbouncer.org).

Included are also other minor fixes and improvements.
  • Loading branch information
kennedykori committed Apr 4, 2023
1 parent 412fc1e commit a22ffba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# Service containers to run with `container-job`
services:
postgres:
image: postgis/postgis:13-3.1
image: postgis/postgis:15-3.3
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
Expand Down
3 changes: 2 additions & 1 deletion config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT", None),
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": True,
"ATOMIC_REQUESTS": False,
"CONN_HEALTH_CHECKS": True,
"CONN_MAX_AGE": env.int("CONN_MAX_AGE", default=60),
},
}
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.9.4
python-3.11

0 comments on commit a22ffba

Please sign in to comment.