summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPrzemysław Suliga <mail@suligap.net>2021-09-26 09:40:29 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-01 07:44:48 +0100
commit4ce59f602ed28320caf3035212cb4d1c5430da2b (patch)
tree71f325ad9521d342ec293070efb510a2d017df45 /docs
parent64c3f049ea3bcb1c82f35ae09f1dd5349a826a5c (diff)
Fixed #30398 -- Added CONN_HEALTH_CHECKS database setting.
The CONN_HEALTH_CHECKS setting can be used to enable database connection health checks for Django's persistent DB connections. Thanks Florian Apolloner for reviews.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/databases.txt15
-rw-r--r--docs/ref/settings.txt20
-rw-r--r--docs/releases/4.1.txt5
3 files changed, 37 insertions, 3 deletions
diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
index 160b5b405e..d4da6bd637 100644
--- a/docs/ref/databases.txt
+++ b/docs/ref/databases.txt
@@ -62,8 +62,19 @@ At the end of each request, Django closes the connection if it has reached its
maximum age or if it is in an unrecoverable error state. If any database
errors have occurred while processing the requests, Django checks whether the
connection still works, and closes it if it doesn't. Thus, database errors
-affect at most one request; if the connection becomes unusable, the next
-request gets a fresh connection.
+affect at most one request per each application's worker thread; if the
+connection becomes unusable, the next request gets a fresh connection.
+
+Setting :setting:`CONN_HEALTH_CHECKS` to ``True`` can be used to improve the
+robustness of connection reuse and prevent errors when a connection has been
+closed by the database server which is now ready to accept and serve new
+connections, e.g. after database server restart. The health check is performed
+only once per request and only if the database is being accessed during the
+handling of the request.
+
+.. versionchanged:: 4.1
+
+ The :setting:`CONN_HEALTH_CHECKS` setting was added.
Caveats
~~~~~~~
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index 54d9c992c9..6c23ba6397 100644
--- a/docs/ref/settings.txt
+++ b/docs/ref/settings.txt
@@ -628,7 +628,25 @@ Default: ``0``
The lifetime of a database connection, as an integer of seconds. Use ``0`` to
close database connections at the end of each request — Django's historical
-behavior — and ``None`` for unlimited persistent connections.
+behavior — and ``None`` for unlimited :ref:`persistent database connections
+<persistent-database-connections>`.
+
+.. setting:: CONN_HEALTH_CHECKS
+
+``CONN_HEALTH_CHECKS``
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. versionadded:: 4.1
+
+Default: ``False``
+
+If set to ``True``, existing :ref:`persistent database connections
+<persistent-database-connections>` will be health checked before they are
+reused in each request performing database access. If the health check fails,
+the connection will be re-established without failing the request when the
+connection is no longer usable but the database server is ready to accept and
+serve new connections (e.g. after database server restart closing existing
+connections).
.. setting:: OPTIONS
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index 34611b4d4d..cc412bebfa 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -208,6 +208,11 @@ Models
:class:`~django.db.models.expressions.Window` expression now accepts string
references to fields and transforms.
+* The new :setting:`CONN_HEALTH_CHECKS` setting allows enabling health checks
+ for :ref:`persistent database connections <persistent-database-connections>`
+ in order to reduce the number of failed requests, e.g. after database server
+ restart.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~