Update documentation for read-only replica (#1384)

This commit is contained in:
Renaud Chaput 2024-01-09 14:38:50 +01:00 committed by GitHub
parent 4eb8473e62
commit a6528ba511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 9 deletions

View File

@ -327,6 +327,38 @@ If provided, takes precedence over `DB_HOST`, `DB_USER`, `DB_NAME`, `DB_PASS` an
Example value: `postgresql://user:password@localhost:5432`
### PostgreSQL (read-only replica) {#postgresql-replica}
{{< hint style="info" >}}
If you want to use a read-only database replica, you can have more details [on this page](../scaling/#read-replicas)
{{</ hint >}}
#### `REPLICA_DB_HOST`
No default.
#### `REPLICA_DB_PORT`
No default.
#### `REPLICA_DB_NAME`
No default.
#### `REPLICA_DB_USER`
No default.
#### `REPLICA_DB_PASS`
No default.
#### `REPLICA_DATABASE_URL`
If provided, takes precedence over `REPLICA_DB_HOST`, `REPLICA_DB_PORT`, `REPLICA_DB_NAME`, `REPLICA_DB_USER` and `REPLICA_DB_PASS`
No default.
### Redis {#redis}
{{< hint style="info" >}}
@ -846,4 +878,3 @@ Defaults to `512`.
#### `GITHUB_API_TOKEN`
Used in a rake task for generating AUTHORS.md from GitHub commit history.

View File

@ -375,7 +375,29 @@ systemctl restart redis-sidekiq.service
## Read-replicas {#read-replicas}
To reduce the load on your PostgreSQL server, you may wish to set up hot streaming replication (read replica). [See this guide for an example](https://cloud.google.com/community/tutorials/setting-up-postgres-hot-standby). You can make use of the replica in Mastodon in these ways:
To reduce the load on your PostgreSQL server, you may wish to set up hot streaming replication (read replica). [See this guide for an example](https://cloud.google.com/community/tutorials/setting-up-postgres-hot-standby).
### Mastodon >= 4.2
Mastodon has built-in replica support starting with version 4.2. You can use the same configuration for every service (Sidekiq included), and some queries will be directed to your read-only replica, when possible, using Rails's built-in replica support. If your replica is lagging behind for more than a few seconds, then the app will stop sending it queries until it catches up.
To configure it, use the following environment variables:
```
REPLICA_DB_HOST
REPLICA_DB_PORT
REPLICA_DB_NAME
REPLICA_DB_USER
REPLICA_DB_PASS
```
Alternatively, you can also use `REPLICA_DATABASE_URL` if you want to configure them all using the same variable.
Once done, this is all good and you should start seeing requests against your replica server!
### Mastodon <= 4.1
For Mastodon versions before 4.2, you can make use of the replica in Mastodon in these ways:
* The streaming API server does not issue writes at all, so you can connect it straight to the replica (it is not querying the database very often anyway, so the impact of this is small).
* Use the Makara driver in the web and Sidekiq processes, so that writes go to the master database, while reads go to the replica. Lets talk about that.