@@ -1257,6 +1257,98 @@ database:
12571257 cp_max: 10
12581258` ` `
12591259---
1260+ # ## `databases`
1261+
1262+ The `databases` option allows specifying a mapping between certain database tables and
1263+ database host details, spreading the load of a single Synapse instance across multiple
1264+ database backends. This is often referred to as "database sharding". This option is only
1265+ supported for PostgreSQL database backends.
1266+
1267+ **Important note:** This is a supported option, but is not currently used in production by the
1268+ Matrix.org Foundation. Proceed with caution and always make backups.
1269+
1270+ ` databases` is a dictionary of arbitrarily-named database entries. Each entry is equivalent
1271+ to the value of the `database` homeserver config option (see above), with the addition of
1272+ a `data_stores` key. `data_stores` is an array of strings that specifies the data store(s)
1273+ (a defined label for a set of tables) that should be stored on the associated database
1274+ backend entry.
1275+
1276+ The currently defined values for `data_stores` are :
1277+
1278+ * `"state"`: Database that relates to state groups will be stored in this database.
1279+
1280+ Specifically, that means the following tables :
1281+ * `state_groups`
1282+ * `state_group_edges`
1283+ * `state_groups_state`
1284+
1285+ And the following sequences :
1286+ * `state_groups_seq_id`
1287+
1288+ * `"main"`: All other database tables and sequences.
1289+
1290+ All databases will end up with additional tables used for tracking database schema migrations
1291+ and any pending background updates. Synapse will create these automatically on startup when checking for
1292+ and/or performing database schema migrations.
1293+
1294+ To migrate an existing database configuration (e.g. all tables on a single database) to a different
1295+ configuration (e.g. the "main" data store on one database, and "state" on another), do the following :
1296+
1297+ 1. Take a backup of your existing database. Things can and do go wrong and database corruption is no joke!
1298+ 2. Ensure all pending database migrations have been applied and background updates have run. The simplest
1299+ way to do this is to use the `update_synapse_database` script supplied with your Synapse installation.
1300+
1301+ ` ` ` sh
1302+ update_synapse_database --database-config homeserver.yaml --run-background-updates
1303+ ` ` `
1304+
1305+ 3. Copy over the necessary tables and sequences from one database to the other. Tables relating to database
1306+ migrations, schemas, schema versions and background updates should **not** be copied.
1307+
1308+ As an example, say that you'd like to split out the "state" data store from an existing database which
1309+ currently contains all data stores.
1310+
1311+ Simply copy the tables and sequences defined above for the "state" datastore from the existing database
1312+ to the secondary database. As noted above, additional tables will be created in the secondary database
1313+ when Synapse is started.
1314+
1315+ 4. Modify/create the `databases` option in your `homeserver.yaml` to match the desired database configuration.
1316+ 5. Start Synapse. Check that it starts up successfully and that things generally seem to be working.
1317+ 6. Drop the old tables that were copied in step 3.
1318+
1319+ Only one of the options `database` or `databases` may be specified in your config, but not both.
1320+
1321+ Example configuration :
1322+
1323+ ` ` ` yaml
1324+ databases:
1325+ basement_box:
1326+ name: psycopg2
1327+ txn_limit: 10000
1328+ data_stores: ["main"]
1329+ args:
1330+ user: synapse_user
1331+ password: secretpassword
1332+ database: synapse_main
1333+ host: localhost
1334+ port: 5432
1335+ cp_min: 5
1336+ cp_max: 10
1337+
1338+ my_other_database:
1339+ name: psycopg2
1340+ txn_limit: 10000
1341+ data_stores: ["state"]
1342+ args:
1343+ user: synapse_user
1344+ password: secretpassword
1345+ database: synapse_state
1346+ host: localhost
1347+ port: 5432
1348+ cp_min: 5
1349+ cp_max: 10
1350+ ` ` `
1351+ ---
12601352# # Logging ##
12611353Config options related to logging.
12621354
0 commit comments