Skip to content

Commit 56cc6ce

Browse files
fix(adminmanual): Clarify frequently asked db replica questions
Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
1 parent 6f9d050 commit 56cc6ce

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

admin_manual/configuration_database/replication.rst

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,64 @@ Replication
44

55
.. versionadded:: 29
66

7-
Nextcloud can natively split read and write operations on a database query level. Replicas are only used for reads. The default database connection will be used for writes and causal reads.
7+
Nextcloud can natively split read and write operations at the level of individual database queries. Read-only
8+
replicas serve reads, while the default (primary) database connection handles writes as well as reads that must be
9+
consistent with a preceding write.
10+
11+
.. note::
12+
13+
Nextcloud only routes queries to the endpoints you provide. Setting up the replication itself (provisioning the
14+
replicas, keeping them in sync, and monitoring replication health) is the responsibility of your database
15+
administrator.
16+
17+
Configuration
18+
-------------
19+
20+
Add the read-only replicas to ``config.php`` with the ``dbreplica`` parameter. Each entry describes one replica and
21+
accepts the same connection options as the primary database connection:
822

923
::
1024

1125
'dbreplica' => [
1226
['user' => 'nextcloud', 'password' => 'password1', 'host' => '10.0.3.1', 'dbname' => 'nextcloud'],
1327
['user' => 'nextcloud', 'password' => 'password2', 'host' => '10.0.3.2', 'dbname' => 'nextcloud'],
1428
],
29+
30+
When more than one replica is configured, Nextcloud picks one of them at random for the reads of a given connection.
31+
There is no load weighting or health checking, so if you need balanced or fault-tolerant read distribution, place the
32+
replicas behind your own load balancer and point ``dbreplica`` at it.
33+
34+
How queries are routed
35+
----------------------
36+
37+
Nextcloud does not inspect the SQL to decide where a query goes. The routing is based on which method sends the query:
38+
read operations are sent to a replica, and write operations are sent to the primary.
39+
40+
To avoid reading stale data right after a change, Nextcloud keeps a request consistent with itself: once a request has
41+
written to the database, its subsequent reads are served from the primary as well. This guarantees *read-your-writes*
42+
consistency: data written earlier in the same request is always read back in its up-to-date state.
43+
44+
Connection scope
45+
----------------
46+
47+
This consistency guarantee is scoped to a single PHP process, that is one web request, one cron execution, or one
48+
``occ`` invocation. It is therefore short-lived and does not carry over to other processes.
49+
50+
A single user operation may span more than one request, and there the guarantee no longer applies. Consider two
51+
requests belonging to the same operation:
52+
53+
1. Request 1 creates a row.
54+
2. Request 2 reads that row.
55+
56+
Request 2 does not know about the write in request 1, so it is free to read from a replica. If the two requests arrive
57+
within a shorter timeframe than the replication lag, the replica may not have received the new row yet, the read
58+
returns nothing, and the application logic fails.
59+
60+
.. warning::
61+
62+
Because the consistency guarantee does not span multiple requests, the replicas must not lag significantly behind
63+
the primary. Noticeable replication delay leads to symptoms such as newly created or changed content that seems to
64+
disappear after a page refresh.
65+
66+
For this reason the feature works best with a synchronous, always-consistent cluster such as Galera. Setups with
67+
asynchronous replication are only safe when the replication delay stays negligible.

0 commit comments

Comments
 (0)