Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Make db connection reuse configurable (#11100)

Mika60e0c9e5a553
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95b61491ea..99d0d5badb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,13 @@
# Changelog
+# 3.9.0 [Unreleased]
+
+- Re-enable 5 minute database connection persistence by default - #11074 + #11100 by @NyanKiyoshi
+ <br/>Set `DB_CONN_MAX_AGE=0` to disable this behavior (adds overhead to requests)
+
All notable, unreleased changes to this project will be documented in this file. For the released changes, please visit the [Releases](https://github.com/mirumee/saleor/releases) page.
-# 3.8.0 [Unreleased]
+# 3.8.0
### GraphQL API
- Add ability to filter by slug. #10578 by @kadewu
diff --git a/saleor/settings.py b/saleor/settings.py
index 152730cb26..21061d1502 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -72,6 +72,11 @@ ALLOWED_CLIENT_HOSTS = get_list(ALLOWED_CLIENT_HOSTS)
INTERNAL_IPS = get_list(os.environ.get("INTERNAL_IPS", "127.0.0.1"))
+# Maximum time in seconds Django can keep the database connections opened.
+# Set the value to 0 to disable connection persistence, database connections
+# will be closed after each request.
+DB_CONN_MAX_AGE = int(os.environ.get("DB_CONN_MAX_AGE", 600))
+
DATABASE_CONNECTION_DEFAULT_NAME = "default"
# TODO: For local envs will be activated in separate PR.
# We need to update docs an saleor platform.
@@ -80,13 +85,14 @@ DATABASE_CONNECTION_REPLICA_NAME = "default"
DATABASES = {
DATABASE_CONNECTION_DEFAULT_NAME: dj_database_url.config(
- default="postgres://saleor:saleor@localhost:5432/saleor", conn_max_age=600
+ default="postgres://saleor:saleor@localhost:5432/saleor",
+ conn_max_age=DB_CONN_MAX_AGE,
),
# TODO: We need to add read only user to saleor platfrom, and we need to update
# docs.
# DATABASE_CONNECTION_REPLICA_NAME: dj_database_url.config(
# default="postgres://saleor_read_only:saleor@localhost:5432/saleor",
- # conn_max_age=600,
+ # conn_max_age=DB_CONN_MAX_AGE,
# ),
}