summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-12-05 15:52:49 +0000
committerErik Johnston <erik@matrix.org>2023-12-05 15:52:49 +0000
commit9583a061785f94898c051986f3a2e9e8588878be (patch)
tree3eed655ac5a3316c0c1cc7f4375a056f71ed6e31
parentMerge remote-tracking branch 'origin/develop' into matrix-org-hotfixes (diff)
parentFix upgrading a room without `events` field in power levels (#16725) (diff)
downloadsynapse-9583a061785f94898c051986f3a2e9e8588878be.tar.xz
Merge remote-tracking branch 'origin/develop' into matrix-org-hotfixes
-rw-r--r--.github/workflows/docs-pr-netlify.yaml2
-rw-r--r--changelog.d/16636.feature1
-rw-r--r--changelog.d/16658.misc1
-rw-r--r--changelog.d/16699.feature1
-rw-r--r--changelog.d/16700.doc1
-rw-r--r--changelog.d/16714.doc1
-rw-r--r--changelog.d/16725.bugfix1
-rw-r--r--changelog.d/16729.bugfix1
-rw-r--r--changelog.d/16730.misc1
-rw-r--r--docs/reverse_proxy.md6
-rw-r--r--docs/server_notices.md3
-rw-r--r--docs/usage/configuration/config_documentation.md34
-rw-r--r--poetry.lock78
-rw-r--r--pyproject.toml2
-rw-r--r--synapse/config/experimental.py4
-rw-r--r--synapse/config/server_notices.py2
-rw-r--r--synapse/handlers/profile.py10
-rw-r--r--synapse/handlers/room.py2
-rw-r--r--synapse/rest/admin/federation.py4
-rw-r--r--synapse/rest/client/profile.py31
-rw-r--r--synapse/rest/client/versions.py2
-rw-r--r--synapse/server_notices/server_notices_manager.py15
-rw-r--r--synapse/storage/schema/common/delta/83/10_replica_identity_applied_module_schemas.sql.postgres1
-rw-r--r--synapse/storage/schema/common/delta/83/10_replica_identity_applied_schema_deltas.sql.postgres1
-rw-r--r--synapse/storage/schema/common/delta/83/10_replica_identity_background_updates.sql.postgres1
-rw-r--r--synapse/storage/schema/common/delta/83/10_replica_identity_schema_compat_version.sql.postgres1
-rw-r--r--synapse/storage/schema/common/delta/83/10_replica_identity_schema_version.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_README.md13
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_account_data.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_application_services_txns.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_appservice_room_list.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_appservice_stream_position.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_blocked_rooms.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_cache_invalidation_stream_by_instance.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_current_state_delta_stream.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_current_state_events.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_deleted_pushers.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_auth_providers.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_inbox.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_outbox.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_inbox.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_converted_stream_position.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_in_room.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_last_success.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_pokes.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_cache.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_extremeties.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_resync.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_stream.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_devices.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_keys.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_signatures.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_device_keys_json.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_fallback_keys_json.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_one_time_keys_json.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys_versions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_erased_users.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_auth.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_auth_chain_links.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_backward_extremities.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_edges.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_forward_extremities.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_json.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions_staging.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_last_receipt_stream_id.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_stream_ordering.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_relations.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_search.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_to_state_groups.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_event_txn_id_device_id.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_events.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_federation_inbound_events_staging.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_federation_stream_position.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_ignored_users.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_local_current_membership.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_thumbnails.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_url_cache.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_monthly_active_users.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_events.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_rooms_servers.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_presence_stream.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_profiles.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_push_rules_stream.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_ratelimit_override.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_receipts_graph.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_receipts_linearized.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_received_transactions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_redactions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_registration_tokens.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_rejections.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache_thumbnails.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_account_data.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_alias_servers.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_aliases.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_depth.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_forgetter_stream_pos.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_memberships.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_earliest_token.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_state.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_tags.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_room_tags_revisions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_server_keys_json.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_server_signature_keys.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_sessions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_state_events.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_stats_incremental_position.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_stream_ordering_to_exterm.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_stream_positions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_threads.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_threepid_guest_access_tokens.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_timeline_gaps.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_credentials.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_ips.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_daily_visits.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_directory.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_search.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_stream_pos.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_external_ids.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_filters.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_ips.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_signature_stream.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_threepid_id_server.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_user_threepids.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_users.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_users_in_public_rooms.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_users_pending_deactivation.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_users_who_share_private_rooms.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_worker_locks.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks.sql.postgres1
-rw-r--r--synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks_mode.sql.postgres1
-rw-r--r--synapse/storage/schema/state/delta/83/10_replica_identity_state_group_edges.sql.postgres1
-rw-r--r--synapse/storage/schema/state/delta/83/10_replica_identity_state_groups_state.sql.postgres1
-rw-r--r--tests/rest/admin/test_server_notice.py27
-rw-r--r--tests/rest/client/test_profile.py160
-rw-r--r--tests/rest/client/test_upgrade_room.py28
-rw-r--r--tests/storage/test_database.py85
142 files changed, 572 insertions, 59 deletions
diff --git a/.github/workflows/docs-pr-netlify.yaml b/.github/workflows/docs-pr-netlify.yaml
index b443cd87d1..8b20322308 100644
--- a/.github/workflows/docs-pr-netlify.yaml
+++ b/.github/workflows/docs-pr-netlify.yaml
@@ -22,7 +22,7 @@ jobs:
           path: book
 
       - name: 📤 Deploy to Netlify
-        uses: matrix-org/netlify-pr-preview@v2
+        uses: matrix-org/netlify-pr-preview@v3
         with:
           path: book
           owner: ${{ github.event.workflow_run.head_repository.owner.login }}
diff --git a/changelog.d/16636.feature b/changelog.d/16636.feature
new file mode 100644
index 0000000000..a363eaafaf
--- /dev/null
+++ b/changelog.d/16636.feature
@@ -0,0 +1 @@
+Support MSC4069: Inhibit profile propagation.
\ No newline at end of file
diff --git a/changelog.d/16658.misc b/changelog.d/16658.misc
new file mode 100644
index 0000000000..baee042f2f
--- /dev/null
+++ b/changelog.d/16658.misc
@@ -0,0 +1 @@
+Add a Postgres `REPLICA IDENTITY` to tables that do not have an implicit one. This should allow use of Postgres logical replication.
\ No newline at end of file
diff --git a/changelog.d/16699.feature b/changelog.d/16699.feature
new file mode 100644
index 0000000000..7ede50f326
--- /dev/null
+++ b/changelog.d/16699.feature
@@ -0,0 +1 @@
+Add an autojoin setting for the notices room so users get joined directly instead of receiving an invite.
diff --git a/changelog.d/16700.doc b/changelog.d/16700.doc
new file mode 100644
index 0000000000..0d55ad338a
--- /dev/null
+++ b/changelog.d/16700.doc
@@ -0,0 +1 @@
+Switch the example UNIX socket paths to /run. Add HAProxy example configuration for UNIX sockets.
diff --git a/changelog.d/16714.doc b/changelog.d/16714.doc
new file mode 100644
index 0000000000..511d2b6022
--- /dev/null
+++ b/changelog.d/16714.doc
@@ -0,0 +1 @@
+Add documentation for how to validate the configuration file with synapse.config script.
diff --git a/changelog.d/16725.bugfix b/changelog.d/16725.bugfix
new file mode 100644
index 0000000000..42dc249fb9
--- /dev/null
+++ b/changelog.d/16725.bugfix
@@ -0,0 +1 @@
+Fix a bug introduced in Synapse 1.7.2 where rooms whose power levels lacked an `events` field could not be upgraded.
diff --git a/changelog.d/16729.bugfix b/changelog.d/16729.bugfix
new file mode 100644
index 0000000000..50e72ac1f8
--- /dev/null
+++ b/changelog.d/16729.bugfix
@@ -0,0 +1 @@
+Fix GET /_synapse/admin/v1/federation/destinations returning null (instead of 0) for `retry_last_ts` and `retry_interval`.
diff --git a/changelog.d/16730.misc b/changelog.d/16730.misc
new file mode 100644
index 0000000000..baee042f2f
--- /dev/null
+++ b/changelog.d/16730.misc
@@ -0,0 +1 @@
+Add a Postgres `REPLICA IDENTITY` to tables that do not have an implicit one. This should allow use of Postgres logical replication.
\ No newline at end of file
diff --git a/docs/reverse_proxy.md b/docs/reverse_proxy.md
index fe9519b4b6..20854035d1 100644
--- a/docs/reverse_proxy.md
+++ b/docs/reverse_proxy.md
@@ -181,7 +181,11 @@ frontend matrix-federation
 backend matrix
   server matrix 127.0.0.1:8008
 ```
-
+Example configuration, if using a UNIX socket. The configuration lines regarding the frontends do not need to be modified.
+```
+backend matrix
+  server matrix unix@/run/synapse/main_public.sock
+```
 
 [Delegation](delegate.md) example:
 ```
diff --git a/docs/server_notices.md b/docs/server_notices.md
index 339d10a0ab..aae25d23b8 100644
--- a/docs/server_notices.md
+++ b/docs/server_notices.md
@@ -46,6 +46,7 @@ server_notices:
    system_mxid_display_name: "Server Notices"
    system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
    room_name: "Server Notices"
+   auto_join: true
 ```
 
 The only compulsory setting is `system_mxid_localpart`, which defines the user
@@ -55,6 +56,8 @@ room which will be created.
 `system_mxid_display_name` and `system_mxid_avatar_url` can be used to set the
 displayname and avatar of the Server Notices user.
 
+`auto_join` will autojoin users to the notices room instead of sending an invite.
+
 ## Sending notices
 
 To send server notices to users you can use the
diff --git a/docs/usage/configuration/config_documentation.md b/docs/usage/configuration/config_documentation.md
index 7c4e742cd5..425ec75542 100644
--- a/docs/usage/configuration/config_documentation.md
+++ b/docs/usage/configuration/config_documentation.md
@@ -33,6 +33,23 @@ In addition, configuration options referring to size use the following suffixes:
 For example, setting `max_avatar_size: 10M` means that Synapse will not accept files larger than 10,485,760 bytes
 for a user avatar.
 
+## Config Validation
+
+The configuration file can be validated with the following command:
+```bash
+python -m synapse.config read <config key to print> -c <path to config>
+```
+
+To validate the entire file, omit `read <config key to print>`:
+```bash
+python -m synapse.config -c <path to config>
+```
+
+To see how to set other options, check the help reference:
+```bash
+python -m synapse.config --help
+```
+
 ### YAML
 The configuration file is a [YAML](https://yaml.org/) file, which means that certain syntax rules
 apply if you want your config file to be read properly. A few helpful things to know:
@@ -566,7 +583,7 @@ listeners:
   # Note that x_forwarded will default to true, when using a UNIX socket. Please see
   # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
   #
-  - path: /var/run/synapse/main_public.sock
+  - path: /run/synapse/main_public.sock
     type: http
     resources:
       - names: [client, federation]
@@ -3815,6 +3832,8 @@ Sub-options for this setting include:
 * `system_mxid_display_name`: set the display name of the "notices" user
 * `system_mxid_avatar_url`: set the avatar for the "notices" user
 * `room_name`: set the room name of the server notices room
+* `auto_join`: boolean. If true, the user will be automatically joined to the room instead of being invited.
+  Defaults to false. _Added in Synapse 1.98.0._
 
 Example configuration:
 ```yaml
@@ -3823,6 +3842,7 @@ server_notices:
   system_mxid_display_name: "Server Notices"
   system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
   room_name: "Server Notices"
+  auto_join: true
 ```
 ---
 ### `enable_room_list_search`
@@ -4215,9 +4235,9 @@ Example configuration(#2, for UNIX sockets):
 ```yaml
 instance_map:
   main:
-    path: /var/run/synapse/main_replication.sock
+    path: /run/synapse/main_replication.sock
   worker1:
-    path: /var/run/synapse/worker1_replication.sock
+    path: /run/synapse/worker1_replication.sock
 ```
 ---
 ### `stream_writers`
@@ -4403,13 +4423,13 @@ Example configuration(#2, using UNIX sockets with a `replication` listener):
 ```yaml
 worker_listeners:
   - type: http
-    path: /var/run/synapse/worker_public.sock
+    path: /run/synapse/worker_replication.sock
     resources:
-      - names: [client, federation]
+      - names: [replication]
   - type: http
-    path: /var/run/synapse/worker_replication.sock
+    path: /run/synapse/worker_public.sock
     resources:
-      - names: [replication]
+      - names: [client, federation]
 ```
 ---
 ### `worker_manhole`
diff --git a/poetry.lock b/poetry.lock
index dd99f39ab7..89387db20a 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -454,34 +454,34 @@ files = [
 
 [[package]]
 name = "cryptography"
-version = "41.0.6"
+version = "41.0.7"
 description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
 optional = false
 python-versions = ">=3.7"
 files = [
-    {file = "cryptography-41.0.6-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:0f27acb55a4e77b9be8d550d762b0513ef3fc658cd3eb15110ebbcbd626db12c"},
-    {file = "cryptography-41.0.6-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:ae236bb8760c1e55b7a39b6d4d32d2279bc6c7c8500b7d5a13b6fb9fc97be35b"},
-    {file = "cryptography-41.0.6-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afda76d84b053923c27ede5edc1ed7d53e3c9f475ebaf63c68e69f1403c405a8"},
-    {file = "cryptography-41.0.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:da46e2b5df770070412c46f87bac0849b8d685c5f2679771de277a422c7d0b86"},
-    {file = "cryptography-41.0.6-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:ff369dd19e8fe0528b02e8df9f2aeb2479f89b1270d90f96a63500afe9af5cae"},
-    {file = "cryptography-41.0.6-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:b648fe2a45e426aaee684ddca2632f62ec4613ef362f4d681a9a6283d10e079d"},
-    {file = "cryptography-41.0.6-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:5daeb18e7886a358064a68dbcaf441c036cbdb7da52ae744e7b9207b04d3908c"},
-    {file = "cryptography-41.0.6-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:068bc551698c234742c40049e46840843f3d98ad7ce265fd2bd4ec0d11306596"},
-    {file = "cryptography-41.0.6-cp37-abi3-win32.whl", hash = "sha256:2132d5865eea673fe6712c2ed5fb4fa49dba10768bb4cc798345748380ee3660"},
-    {file = "cryptography-41.0.6-cp37-abi3-win_amd64.whl", hash = "sha256:48783b7e2bef51224020efb61b42704207dde583d7e371ef8fc2a5fb6c0aabc7"},
-    {file = "cryptography-41.0.6-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:8efb2af8d4ba9dbc9c9dd8f04d19a7abb5b49eab1f3694e7b5a16a5fc2856f5c"},
-    {file = "cryptography-41.0.6-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c5a550dc7a3b50b116323e3d376241829fd326ac47bc195e04eb33a8170902a9"},
-    {file = "cryptography-41.0.6-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:85abd057699b98fce40b41737afb234fef05c67e116f6f3650782c10862c43da"},
-    {file = "cryptography-41.0.6-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:f39812f70fc5c71a15aa3c97b2bbe213c3f2a460b79bd21c40d033bb34a9bf36"},
-    {file = "cryptography-41.0.6-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:742ae5e9a2310e9dade7932f9576606836ed174da3c7d26bc3d3ab4bd49b9f65"},
-    {file = "cryptography-41.0.6-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:35f3f288e83c3f6f10752467c48919a7a94b7d88cc00b0668372a0d2ad4f8ead"},
-    {file = "cryptography-41.0.6-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:4d03186af98b1c01a4eda396b137f29e4e3fb0173e30f885e27acec8823c1b09"},
-    {file = "cryptography-41.0.6-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:b27a7fd4229abef715e064269d98a7e2909ebf92eb6912a9603c7e14c181928c"},
-    {file = "cryptography-41.0.6-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:398ae1fc711b5eb78e977daa3cbf47cec20f2c08c5da129b7a296055fbb22aed"},
-    {file = "cryptography-41.0.6-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:7e00fb556bda398b99b0da289ce7053639d33b572847181d6483ad89835115f6"},
-    {file = "cryptography-41.0.6-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:60e746b11b937911dc70d164060d28d273e31853bb359e2b2033c9e93e6f3c43"},
-    {file = "cryptography-41.0.6-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:3288acccef021e3c3c10d58933f44e8602cf04dba96d9796d70d537bb2f4bbc4"},
-    {file = "cryptography-41.0.6.tar.gz", hash = "sha256:422e3e31d63743855e43e5a6fcc8b4acab860f560f9321b0ee6269cc7ed70cc3"},
+    {file = "cryptography-41.0.7-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:3c78451b78313fa81607fa1b3f1ae0a5ddd8014c38a02d9db0616133987b9cdf"},
+    {file = "cryptography-41.0.7-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:928258ba5d6f8ae644e764d0f996d61a8777559f72dfeb2eea7e2fe0ad6e782d"},
+    {file = "cryptography-41.0.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5a1b41bc97f1ad230a41657d9155113c7521953869ae57ac39ac7f1bb471469a"},
+    {file = "cryptography-41.0.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:841df4caa01008bad253bce2a6f7b47f86dc9f08df4b433c404def869f590a15"},
+    {file = "cryptography-41.0.7-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:5429ec739a29df2e29e15d082f1d9ad683701f0ec7709ca479b3ff2708dae65a"},
+    {file = "cryptography-41.0.7-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:43f2552a2378b44869fe8827aa19e69512e3245a219104438692385b0ee119d1"},
+    {file = "cryptography-41.0.7-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:af03b32695b24d85a75d40e1ba39ffe7db7ffcb099fe507b39fd41a565f1b157"},
+    {file = "cryptography-41.0.7-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:49f0805fc0b2ac8d4882dd52f4a3b935b210935d500b6b805f321addc8177406"},
+    {file = "cryptography-41.0.7-cp37-abi3-win32.whl", hash = "sha256:f983596065a18a2183e7f79ab3fd4c475205b839e02cbc0efbbf9666c4b3083d"},
+    {file = "cryptography-41.0.7-cp37-abi3-win_amd64.whl", hash = "sha256:90452ba79b8788fa380dfb587cca692976ef4e757b194b093d845e8d99f612f2"},
+    {file = "cryptography-41.0.7-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:079b85658ea2f59c4f43b70f8119a52414cdb7be34da5d019a77bf96d473b960"},
+    {file = "cryptography-41.0.7-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:b640981bf64a3e978a56167594a0e97db71c89a479da8e175d8bb5be5178c003"},
+    {file = "cryptography-41.0.7-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e3114da6d7f95d2dee7d3f4eec16dacff819740bbab931aff8648cb13c5ff5e7"},
+    {file = "cryptography-41.0.7-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:d5ec85080cce7b0513cfd233914eb8b7bbd0633f1d1703aa28d1dd5a72f678ec"},
+    {file = "cryptography-41.0.7-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:7a698cb1dac82c35fcf8fe3417a3aaba97de16a01ac914b89a0889d364d2f6be"},
+    {file = "cryptography-41.0.7-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:37a138589b12069efb424220bf78eac59ca68b95696fc622b6ccc1c0a197204a"},
+    {file = "cryptography-41.0.7-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:68a2dec79deebc5d26d617bfdf6e8aab065a4f34934b22d3b5010df3ba36612c"},
+    {file = "cryptography-41.0.7-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:09616eeaef406f99046553b8a40fbf8b1e70795a91885ba4c96a70793de5504a"},
+    {file = "cryptography-41.0.7-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:48a0476626da912a44cc078f9893f292f0b3e4c739caf289268168d8f4702a39"},
+    {file = "cryptography-41.0.7-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c7f3201ec47d5207841402594f1d7950879ef890c0c495052fa62f58283fde1a"},
+    {file = "cryptography-41.0.7-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:c5ca78485a255e03c32b513f8c2bc39fedb7f5c5f8535545bdc223a03b24f248"},
+    {file = "cryptography-41.0.7-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:d6c391c021ab1f7a82da5d8d0b3cee2f4b2c455ec86c8aebbc84837a631ff309"},
+    {file = "cryptography-41.0.7.tar.gz", hash = "sha256:13f93ce9bea8016c253b34afc6bd6a75993e5c40672ed5405a9c832f0d4a00bc"},
 ]
 
 [package.dependencies]
@@ -712,13 +712,13 @@ idna = ">=2.5"
 
 [[package]]
 name = "idna"
-version = "3.4"
+version = "3.6"
 description = "Internationalized Domain Names in Applications (IDNA)"
 optional = false
 python-versions = ">=3.5"
 files = [
-    {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"},
-    {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"},
+    {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"},
+    {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"},
 ]
 
 [[package]]
@@ -1611,13 +1611,13 @@ files = [
 
 [[package]]
 name = "phonenumbers"
-version = "8.13.23"
+version = "8.13.26"
 description = "Python version of Google's common library for parsing, formatting, storing and validating international phone numbers."
 optional = false
 python-versions = "*"
 files = [
-    {file = "phonenumbers-8.13.23-py2.py3-none-any.whl", hash = "sha256:34d6cb279dd4a64714e324c71350f96e5bda3237be28d11b4c555c44701544cd"},
-    {file = "phonenumbers-8.13.23.tar.gz", hash = "sha256:869e44fcaaf276eca6b953a401e2b27d57461f3a18a66cf5f13377e7bb0e228c"},
+    {file = "phonenumbers-8.13.26-py2.py3-none-any.whl", hash = "sha256:b2308c9c5750b8f10dd30d94547afd66bce60ac5e93aff227f95740557f32752"},
+    {file = "phonenumbers-8.13.26.tar.gz", hash = "sha256:937d70aeceb317f5831dfec28de855a60260ef4a9d551964bec8e7a7d0cf81cd"},
 ]
 
 [[package]]
@@ -2691,17 +2691,17 @@ test = ["cython", "filelock", "html5lib", "pytest (>=4.6)"]
 
 [[package]]
 name = "sphinx-autodoc2"
-version = "0.4.2"
+version = "0.5.0"
 description = "Analyse a python project and create documentation for it."
 optional = false
 python-versions = ">=3.8"
 files = [
-    {file = "sphinx-autodoc2-0.4.2.tar.gz", hash = "sha256:06da226a25a4339e173b34bb0e590e0ba9b4570b414796140aee1939d09acb3a"},
-    {file = "sphinx_autodoc2-0.4.2-py3-none-any.whl", hash = "sha256:00835ba8c980b9c510ea794c3e2060e5a254a74c6c22badc9bfd3642dc1034b4"},
+    {file = "sphinx_autodoc2-0.5.0-py3-none-any.whl", hash = "sha256:e867013b1512f9d6d7e6f6799f8b537d6884462acd118ef361f3f619a60b5c9e"},
+    {file = "sphinx_autodoc2-0.5.0.tar.gz", hash = "sha256:7d76044aa81d6af74447080182b6868c7eb066874edc835e8ddf810735b6565a"},
 ]
 
 [package.dependencies]
-astroid = ">=2.7"
+astroid = ">=2.7,<4"
 tomli = {version = "*", markers = "python_version < \"3.11\""}
 typing-extensions = "*"
 
@@ -2709,7 +2709,7 @@ typing-extensions = "*"
 cli = ["typer[all]"]
 docs = ["furo", "myst-parser", "sphinx (>=4.0.0)"]
 sphinx = ["sphinx (>=4.0.0)"]
-testing = ["pytest", "pytest-cov", "pytest-regressions", "sphinx (>=4.0.0)"]
+testing = ["pytest", "pytest-cov", "pytest-regressions", "sphinx (>=4.0.0,<7)"]
 
 [[package]]
 name = "sphinx-basic-ng"
@@ -3054,13 +3054,13 @@ files = [
 
 [[package]]
 name = "types-jsonschema"
-version = "4.19.0.4"
+version = "4.20.0.0"
 description = "Typing stubs for jsonschema"
 optional = false
 python-versions = ">=3.8"
 files = [
-    {file = "types-jsonschema-4.19.0.4.tar.gz", hash = "sha256:994feb6632818259c4b5dbd733867824cb475029a6abc2c2b5201a2268b6e7d2"},
-    {file = "types_jsonschema-4.19.0.4-py3-none-any.whl", hash = "sha256:b73c3f4ba3cd8108602d1198a438e2698d5eb6b9db206ed89a33e24729b0abe7"},
+    {file = "types-jsonschema-4.20.0.0.tar.gz", hash = "sha256:0de1032d243f1d3dba8b745ad84efe8c1af71665a9deb1827636ac535dcb79c1"},
+    {file = "types_jsonschema-4.20.0.0-py3-none-any.whl", hash = "sha256:e6d5df18aaca4412f0aae246a294761a92040e93d7bc840f002b7329a8b72d26"},
 ]
 
 [package.dependencies]
@@ -3432,4 +3432,4 @@ user-search = ["pyicu"]
 [metadata]
 lock-version = "2.0"
 python-versions = "^3.8.0"
-content-hash = "2924e80a14b32b430e70bafbd2b00893a365d9c3836c026296f4af0b9579e604"
+content-hash = "57716a9580b3493c3d2038492a6d4c36d1d16a79c5a0880b6eadcaf681503d3a"
diff --git a/pyproject.toml b/pyproject.toml
index b0ccf82e10..eeede837d0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -370,7 +370,7 @@ optional = true
 
 [tool.poetry.group.dev-docs.dependencies]
 sphinx = {version = "^6.1", python = "^3.8"}
-sphinx-autodoc2 = {version = "^0.4.2", python = "^3.8"}
+sphinx-autodoc2 = {version = ">=0.4.2,<0.6.0", python = "^3.8"}
 myst-parser = {version = "^1.0.0", python = "^3.8"}
 furo = ">=2022.12.7,<2024.0.0"
 
diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py
index 9f830e7094..6b9febe5a7 100644
--- a/synapse/config/experimental.py
+++ b/synapse/config/experimental.py
@@ -419,3 +419,7 @@ class ExperimentalConfig(Config):
         self.msc4028_push_encrypted_events = experimental.get(
             "msc4028_push_encrypted_events", False
         )
+
+        self.msc4069_profile_inhibit_propagation = experimental.get(
+            "msc4069_profile_inhibit_propagation", False
+        )
diff --git a/synapse/config/server_notices.py b/synapse/config/server_notices.py
index ce041abe9b..a8badba0f8 100644
--- a/synapse/config/server_notices.py
+++ b/synapse/config/server_notices.py
@@ -48,6 +48,7 @@ class ServerNoticesConfig(Config):
         self.server_notices_mxid_display_name: Optional[str] = None
         self.server_notices_mxid_avatar_url: Optional[str] = None
         self.server_notices_room_name: Optional[str] = None
+        self.server_notices_auto_join: bool = False
 
     def read_config(self, config: JsonDict, **kwargs: Any) -> None:
         c = config.get("server_notices")
@@ -62,3 +63,4 @@ class ServerNoticesConfig(Config):
         self.server_notices_mxid_avatar_url = c.get("system_mxid_avatar_url", None)
         # todo: i18n
         self.server_notices_room_name = c.get("room_name", "Server Notices")
+        self.server_notices_auto_join = c.get("auto_join", False)
diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index 1027fbfd28..e043fd5322 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -129,6 +129,7 @@ class ProfileHandler:
         new_displayname: str,
         by_admin: bool = False,
         deactivation: bool = False,
+        propagate: bool = True,
     ) -> None:
         """Set the displayname of a user
 
@@ -138,6 +139,7 @@ class ProfileHandler:
             new_displayname: The displayname to give this user.
             by_admin: Whether this change was made by an administrator.
             deactivation: Whether this change was made while deactivating the user.
+            propagate: Whether this change also applies to the user's membership events.
         """
         if not self.hs.is_mine(target_user):
             raise SynapseError(400, "User is not hosted on this homeserver")
@@ -188,7 +190,8 @@ class ProfileHandler:
             target_user.to_string(), profile, by_admin, deactivation
         )
 
-        await self._update_join_states(requester, target_user)
+        if propagate:
+            await self._update_join_states(requester, target_user)
 
     async def get_avatar_url(self, target_user: UserID) -> Optional[str]:
         if self.hs.is_mine(target_user):
@@ -221,6 +224,7 @@ class ProfileHandler:
         new_avatar_url: str,
         by_admin: bool = False,
         deactivation: bool = False,
+        propagate: bool = True,
     ) -> None:
         """Set a new avatar URL for a user.
 
@@ -230,6 +234,7 @@ class ProfileHandler:
             new_avatar_url: The avatar URL to give this user.
             by_admin: Whether this change was made by an administrator.
             deactivation: Whether this change was made while deactivating the user.
+            propagate: Whether this change also applies to the user's membership events.
         """
         if not self.hs.is_mine(target_user):
             raise SynapseError(400, "User is not hosted on this homeserver")
@@ -278,7 +283,8 @@ class ProfileHandler:
             target_user.to_string(), profile, by_admin, deactivation
         )
 
-        await self._update_join_states(requester, target_user)
+        if propagate:
+            await self._update_join_states(requester, target_user)
 
     @cached()
     async def check_avatar_size_and_mime_type(self, mxc: str) -> bool:
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index f865bed1ec..2823ca6f0d 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -549,7 +549,7 @@ class RoomCreationHandler:
         except (TypeError, ValueError):
             ban = 50
         needed_power_level = max(
-            state_default_int, ban, max(event_power_levels.values())
+            state_default_int, ban, max(event_power_levels.values(), default=0)
         )
 
         # Get the user's current power level, this matches the logic in get_user_power_level,
diff --git a/synapse/rest/admin/federation.py b/synapse/rest/admin/federation.py
index a6ce787da1..2f238f0217 100644
--- a/synapse/rest/admin/federation.py
+++ b/synapse/rest/admin/federation.py
@@ -89,8 +89,8 @@ class ListDestinationsRestServlet(RestServlet):
             "destinations": [
                 {
                     "destination": r[0],
-                    "retry_last_ts": r[1],
-                    "retry_interval": r[2],
+                    "retry_last_ts": r[1] or 0,
+                    "retry_interval": r[2] or 0,
                     "failure_ts": r[3],
                     "last_successful_stream_ordering": r[4],
                 }
diff --git a/synapse/rest/client/profile.py b/synapse/rest/client/profile.py
index 493e1acea0..12d3da1ced 100644
--- a/synapse/rest/client/profile.py
+++ b/synapse/rest/client/profile.py
@@ -13,12 +13,17 @@
 # limitations under the License.
 
 """ This module contains REST servlets to do with profile: /profile/<paths> """
+
 from http import HTTPStatus
 from typing import TYPE_CHECKING, Tuple
 
 from synapse.api.errors import Codes, SynapseError
 from synapse.http.server import HttpServer
-from synapse.http.servlet import RestServlet, parse_json_object_from_request
+from synapse.http.servlet import (
+    RestServlet,
+    parse_boolean,
+    parse_json_object_from_request,
+)
 from synapse.http.site import SynapseRequest
 from synapse.rest.client._base import client_patterns
 from synapse.types import JsonDict, UserID
@@ -27,6 +32,20 @@ if TYPE_CHECKING:
     from synapse.server import HomeServer
 
 
+def _read_propagate(hs: "HomeServer", request: SynapseRequest) -> bool:
+    # This will always be set by the time Twisted calls us.
+    assert request.args is not None
+
+    propagate = True
+    if hs.config.experimental.msc4069_profile_inhibit_propagation:
+        do_propagate = request.args.get(b"org.matrix.msc4069.propagate")
+        if do_propagate is not None:
+            propagate = parse_boolean(
+                request, "org.matrix.msc4069.propagate", default=False
+            )
+    return propagate
+
+
 class ProfileDisplaynameRestServlet(RestServlet):
     PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/displayname", v1=True)
     CATEGORY = "Event sending requests"
@@ -80,7 +99,11 @@ class ProfileDisplaynameRestServlet(RestServlet):
                 errcode=Codes.BAD_JSON,
             )
 
-        await self.profile_handler.set_displayname(user, requester, new_name, is_admin)
+        propagate = _read_propagate(self.hs, request)
+
+        await self.profile_handler.set_displayname(
+            user, requester, new_name, is_admin, propagate=propagate
+        )
 
         return 200, {}
 
@@ -135,8 +158,10 @@ class ProfileAvatarURLRestServlet(RestServlet):
                 400, "Missing key 'avatar_url'", errcode=Codes.MISSING_PARAM
             )
 
+        propagate = _read_propagate(self.hs, request)
+
         await self.profile_handler.set_avatar_url(
-            user, requester, new_avatar_url, is_admin
+            user, requester, new_avatar_url, is_admin, propagate=propagate
         )
 
         return 200, {}
diff --git a/synapse/rest/client/versions.py b/synapse/rest/client/versions.py
index f4d19e0470..54c01bb739 100644
--- a/synapse/rest/client/versions.py
+++ b/synapse/rest/client/versions.py
@@ -129,6 +129,8 @@ class VersionsRestServlet(RestServlet):
                     "org.matrix.msc3981": self.config.experimental.msc3981_recurse_relations,
                     # Adds support for deleting account data.
                     "org.matrix.msc3391": self.config.experimental.msc3391_enabled,
+                    # Allows clients to inhibit profile update propagation.
+                    "org.matrix.msc4069": self.config.experimental.msc4069_profile_inhibit_propagation,
                 },
             },
         )
diff --git a/synapse/server_notices/server_notices_manager.py b/synapse/server_notices/server_notices_manager.py
index 44b999677a..2353b5d47f 100644
--- a/synapse/server_notices/server_notices_manager.py
+++ b/synapse/server_notices/server_notices_manager.py
@@ -224,14 +224,27 @@ class ServerNoticesManager:
             if room.room_id == room_id:
                 return
 
+        user_id_obj = UserID.from_string(user_id)
         await self._room_member_handler.update_membership(
             requester=requester,
-            target=UserID.from_string(user_id),
+            target=user_id_obj,
             room_id=room_id,
             action="invite",
             ratelimit=False,
         )
 
+        if self._config.servernotices.server_notices_auto_join:
+            user_requester = create_requester(
+                user_id, authenticated_entity=self._server_name
+            )
+            await self._room_member_handler.update_membership(
+                requester=user_requester,
+                target=user_id_obj,
+                room_id=room_id,
+                action="join",
+                ratelimit=False,
+            )
+
     async def _update_notice_user_profile_if_changed(
         self,
         requester: Requester,
diff --git a/synapse/storage/schema/common/delta/83/10_replica_identity_applied_module_schemas.sql.postgres b/synapse/storage/schema/common/delta/83/10_replica_identity_applied_module_schemas.sql.postgres
new file mode 100644
index 0000000000..57c35b6430
--- /dev/null
+++ b/synapse/storage/schema/common/delta/83/10_replica_identity_applied_module_schemas.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE applied_module_schemas REPLICA IDENTITY USING INDEX applied_module_schemas_module_name_file_key;
diff --git a/synapse/storage/schema/common/delta/83/10_replica_identity_applied_schema_deltas.sql.postgres b/synapse/storage/schema/common/delta/83/10_replica_identity_applied_schema_deltas.sql.postgres
new file mode 100644
index 0000000000..1426f9a9e4
--- /dev/null
+++ b/synapse/storage/schema/common/delta/83/10_replica_identity_applied_schema_deltas.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE applied_schema_deltas REPLICA IDENTITY USING INDEX applied_schema_deltas_version_file_key;
diff --git a/synapse/storage/schema/common/delta/83/10_replica_identity_background_updates.sql.postgres b/synapse/storage/schema/common/delta/83/10_replica_identity_background_updates.sql.postgres
new file mode 100644
index 0000000000..f04937b3db
--- /dev/null
+++ b/synapse/storage/schema/common/delta/83/10_replica_identity_background_updates.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE background_updates REPLICA IDENTITY USING INDEX background_updates_uniqueness;
diff --git a/synapse/storage/schema/common/delta/83/10_replica_identity_schema_compat_version.sql.postgres b/synapse/storage/schema/common/delta/83/10_replica_identity_schema_compat_version.sql.postgres
new file mode 100644
index 0000000000..e3a6f7ca4f
--- /dev/null
+++ b/synapse/storage/schema/common/delta/83/10_replica_identity_schema_compat_version.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE schema_compat_version REPLICA IDENTITY USING INDEX schema_compat_version_lock_key;
diff --git a/synapse/storage/schema/common/delta/83/10_replica_identity_schema_version.sql.postgres b/synapse/storage/schema/common/delta/83/10_replica_identity_schema_version.sql.postgres
new file mode 100644
index 0000000000..c10efe0563
--- /dev/null
+++ b/synapse/storage/schema/common/delta/83/10_replica_identity_schema_version.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE schema_version REPLICA IDENTITY USING INDEX schema_version_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_README.md b/synapse/storage/schema/main/delta/83/10_replica_identity_README.md
new file mode 100644
index 0000000000..fd7bdfc7ad
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_README.md
@@ -0,0 +1,13 @@
+The `10_replica_identity_xxx.sql.postgres` series of schema deltas adds replica identities for tables that do not have one implicitly as a result of having a primary key.
+
+This is needed to use logical replication with Synapse (at least without `UPDATE` and `DELETE` statements failing!).
+
+Where possible, we use an existing `UNIQUE` index on `NOT NULL` columns as the replica identity. Otherwise, we have to fall back to using the full row as a replica identity.
+
+Unfortunately, by running all the `ALTER TABLE` statements in one schema delta per database, it was too likely to hit a deadlock as it would only take
+one other transaction from a running Synapse worker to access the tables out of order and trigger a deadlock.
+
+By having each statement in its own delta file, each one is run in its own transaction and only needs to take a very brief (instant) lock on the table but no other tables,
+so there should be no chance of deadlock.
+
+Like many schema deltas we already apply to Synapse, it is probably blocked by an ongoing `pg_dump`.
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_account_data.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_account_data.sql.postgres
new file mode 100644
index 0000000000..1bf720e80e
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_account_data.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE account_data REPLICA IDENTITY USING INDEX account_data_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_application_services_txns.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_application_services_txns.sql.postgres
new file mode 100644
index 0000000000..4ec052ebeb
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_application_services_txns.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE application_services_txns REPLICA IDENTITY USING INDEX application_services_txns_as_id_txn_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_room_list.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_room_list.sql.postgres
new file mode 100644
index 0000000000..232a628ca2
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_room_list.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE appservice_room_list REPLICA IDENTITY USING INDEX appservice_room_list_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_stream_position.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_stream_position.sql.postgres
new file mode 100644
index 0000000000..e870a68723
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_appservice_stream_position.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE appservice_stream_position REPLICA IDENTITY USING INDEX appservice_stream_position_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_blocked_rooms.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_blocked_rooms.sql.postgres
new file mode 100644
index 0000000000..e3fce4045f
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_blocked_rooms.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE blocked_rooms REPLICA IDENTITY USING INDEX blocked_rooms_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_cache_invalidation_stream_by_instance.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_cache_invalidation_stream_by_instance.sql.postgres
new file mode 100644
index 0000000000..4fd87faaf6
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_cache_invalidation_stream_by_instance.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE cache_invalidation_stream_by_instance REPLICA IDENTITY USING INDEX cache_invalidation_stream_by_instance_id;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_delta_stream.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_delta_stream.sql.postgres
new file mode 100644
index 0000000000..b618286e8a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_delta_stream.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE current_state_delta_stream REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_events.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_events.sql.postgres
new file mode 100644
index 0000000000..b058a9f06e
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_current_state_events.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE current_state_events REPLICA IDENTITY USING INDEX current_state_events_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_deleted_pushers.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_deleted_pushers.sql.postgres
new file mode 100644
index 0000000000..0b4fcc5ae1
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_deleted_pushers.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE deleted_pushers REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_auth_providers.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_auth_providers.sql.postgres
new file mode 100644
index 0000000000..8e02438b47
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_auth_providers.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_auth_providers REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_inbox.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_inbox.sql.postgres
new file mode 100644
index 0000000000..547e485f00
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_inbox.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_federation_inbox REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_outbox.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_outbox.sql.postgres
new file mode 100644
index 0000000000..809afe4dc5
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_federation_outbox.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_federation_outbox REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_inbox.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_inbox.sql.postgres
new file mode 100644
index 0000000000..07652038a2
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_inbox.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_inbox REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_converted_stream_position.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_converted_stream_position.sql.postgres
new file mode 100644
index 0000000000..8474b8c842
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_converted_stream_position.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_changes_converted_stream_position REPLICA IDENTITY USING INDEX device_lists_changes_converted_stream_position_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_in_room.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_in_room.sql.postgres
new file mode 100644
index 0000000000..712a54bc0f
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_changes_in_room.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_changes_in_room REPLICA IDENTITY USING INDEX device_lists_changes_in_stream_id;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_last_success.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_last_success.sql.postgres
new file mode 100644
index 0000000000..4357690e8d
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_last_success.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_outbound_last_success REPLICA IDENTITY USING INDEX device_lists_outbound_last_success_unique_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_pokes.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_pokes.sql.postgres
new file mode 100644
index 0000000000..cc724877cf
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_outbound_pokes.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_outbound_pokes REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_cache.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_cache.sql.postgres
new file mode 100644
index 0000000000..ea4351c654
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_cache.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_remote_cache REPLICA IDENTITY USING INDEX device_lists_remote_cache_unique_id;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_extremeties.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_extremeties.sql.postgres
new file mode 100644
index 0000000000..9dc3bec6fa
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_extremeties.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_remote_extremeties REPLICA IDENTITY USING INDEX device_lists_remote_extremeties_unique_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_resync.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_resync.sql.postgres
new file mode 100644
index 0000000000..df3cecfb94
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_remote_resync.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_remote_resync REPLICA IDENTITY USING INDEX device_lists_remote_resync_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_stream.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_stream.sql.postgres
new file mode 100644
index 0000000000..30a7922613
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_device_lists_stream.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE device_lists_stream REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_devices.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_devices.sql.postgres
new file mode 100644
index 0000000000..57d54a0dc0
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_devices.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE devices REPLICA IDENTITY USING INDEX device_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_keys.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_keys.sql.postgres
new file mode 100644
index 0000000000..f3f2693631
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_keys.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_cross_signing_keys REPLICA IDENTITY USING INDEX e2e_cross_signing_keys_stream_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_signatures.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_signatures.sql.postgres
new file mode 100644
index 0000000000..d2347b7153
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_cross_signing_signatures.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_cross_signing_signatures REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_device_keys_json.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_device_keys_json.sql.postgres
new file mode 100644
index 0000000000..66dafdc8e1
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_device_keys_json.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_device_keys_json REPLICA IDENTITY USING INDEX e2e_device_keys_json_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_fallback_keys_json.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_fallback_keys_json.sql.postgres
new file mode 100644
index 0000000000..8bb4dfc78b
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_fallback_keys_json.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_fallback_keys_json REPLICA IDENTITY USING INDEX e2e_fallback_keys_json_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_one_time_keys_json.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_one_time_keys_json.sql.postgres
new file mode 100644
index 0000000000..b6609cfdfb
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_one_time_keys_json.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_one_time_keys_json REPLICA IDENTITY USING INDEX e2e_one_time_keys_json_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys.sql.postgres
new file mode 100644
index 0000000000..9b98924165
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_room_keys REPLICA IDENTITY USING INDEX e2e_room_keys_with_version_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys_versions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys_versions.sql.postgres
new file mode 100644
index 0000000000..ac7aaba44d
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_e2e_room_keys_versions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE e2e_room_keys_versions REPLICA IDENTITY USING INDEX e2e_room_keys_versions_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_erased_users.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_erased_users.sql.postgres
new file mode 100644
index 0000000000..c775f81333
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_erased_users.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE erased_users REPLICA IDENTITY USING INDEX erased_users_user;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth.sql.postgres
new file mode 100644
index 0000000000..d8014d123b
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_auth REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth_chain_links.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth_chain_links.sql.postgres
new file mode 100644
index 0000000000..c2f9c90d42
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_auth_chain_links.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_auth_chain_links REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_backward_extremities.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_backward_extremities.sql.postgres
new file mode 100644
index 0000000000..751541a929
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_backward_extremities.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_backward_extremities REPLICA IDENTITY USING INDEX event_backward_extremities_event_id_room_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_edges.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_edges.sql.postgres
new file mode 100644
index 0000000000..066ea763f1
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_edges.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_edges REPLICA IDENTITY USING INDEX event_edges_event_id_prev_event_id_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_forward_extremities.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_forward_extremities.sql.postgres
new file mode 100644
index 0000000000..d70d6fd55c
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_forward_extremities.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_forward_extremities REPLICA IDENTITY USING INDEX event_forward_extremities_event_id_room_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_json.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_json.sql.postgres
new file mode 100644
index 0000000000..b614b96422
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_json.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_json REPLICA IDENTITY USING INDEX event_json_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions.sql.postgres
new file mode 100644
index 0000000000..7a92620270
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_push_actions REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions_staging.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions_staging.sql.postgres
new file mode 100644
index 0000000000..292ed9787d
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_actions_staging.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_push_actions_staging REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary.sql.postgres
new file mode 100644
index 0000000000..42a9b6b676
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_push_summary REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_last_receipt_stream_id.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_last_receipt_stream_id.sql.postgres
new file mode 100644
index 0000000000..707e498a6e
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_last_receipt_stream_id.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_push_summary_last_receipt_stream_id REPLICA IDENTITY USING INDEX event_push_summary_last_receipt_stream_id_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_stream_ordering.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_stream_ordering.sql.postgres
new file mode 100644
index 0000000000..1240e3e1b5
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_push_summary_stream_ordering.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_push_summary_stream_ordering REPLICA IDENTITY USING INDEX event_push_summary_stream_ordering_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_relations.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_relations.sql.postgres
new file mode 100644
index 0000000000..6b62a6bc20
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_relations.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_relations REPLICA IDENTITY USING INDEX event_relations_id;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_search.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_search.sql.postgres
new file mode 100644
index 0000000000..e8467fc3d3
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_search.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_search REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_to_state_groups.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_to_state_groups.sql.postgres
new file mode 100644
index 0000000000..4206975c35
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_to_state_groups.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_to_state_groups REPLICA IDENTITY USING INDEX event_to_state_groups_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_event_txn_id_device_id.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_event_txn_id_device_id.sql.postgres
new file mode 100644
index 0000000000..05fce1e6b0
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_event_txn_id_device_id.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE event_txn_id_device_id REPLICA IDENTITY USING INDEX event_txn_id_device_id_event_id;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_events.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_events.sql.postgres
new file mode 100644
index 0000000000..9046b8eb08
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_events.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE events REPLICA IDENTITY USING INDEX events_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_federation_inbound_events_staging.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_federation_inbound_events_staging.sql.postgres
new file mode 100644
index 0000000000..d9d2f88f67
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_federation_inbound_events_staging.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE federation_inbound_events_staging REPLICA IDENTITY USING INDEX federation_inbound_events_staging_instance_event;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_federation_stream_position.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_federation_stream_position.sql.postgres
new file mode 100644
index 0000000000..5f9df14d7d
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_federation_stream_position.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE federation_stream_position REPLICA IDENTITY USING INDEX federation_stream_position_instance;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_ignored_users.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_ignored_users.sql.postgres
new file mode 100644
index 0000000000..dd082b7f9e
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_ignored_users.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE ignored_users REPLICA IDENTITY USING INDEX ignored_users_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_local_current_membership.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_local_current_membership.sql.postgres
new file mode 100644
index 0000000000..f36bad701a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_local_current_membership.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE local_current_membership REPLICA IDENTITY USING INDEX local_current_membership_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository.sql.postgres
new file mode 100644
index 0000000000..78a5128af3
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE local_media_repository REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_thumbnails.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_thumbnails.sql.postgres
new file mode 100644
index 0000000000..6cd53f8e15
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_thumbnails.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE local_media_repository_thumbnails REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_url_cache.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_url_cache.sql.postgres
new file mode 100644
index 0000000000..a41590ce6b
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_local_media_repository_url_cache.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE local_media_repository_url_cache REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_monthly_active_users.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_monthly_active_users.sql.postgres
new file mode 100644
index 0000000000..326fc279d3
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_monthly_active_users.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE monthly_active_users REPLICA IDENTITY USING INDEX monthly_active_users_users;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_events.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_events.sql.postgres
new file mode 100644
index 0000000000..c6acd84315
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_events.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE partial_state_events REPLICA IDENTITY USING INDEX partial_state_events_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_rooms_servers.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_rooms_servers.sql.postgres
new file mode 100644
index 0000000000..c618660b5f
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_partial_state_rooms_servers.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE partial_state_rooms_servers REPLICA IDENTITY USING INDEX partial_state_rooms_servers_room_id_server_name_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_presence_stream.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_presence_stream.sql.postgres
new file mode 100644
index 0000000000..4e5d8d7a68
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_presence_stream.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE presence_stream REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_profiles.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_profiles.sql.postgres
new file mode 100644
index 0000000000..bb25e7a67a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_profiles.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE profiles REPLICA IDENTITY USING INDEX profiles_user_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_push_rules_stream.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_push_rules_stream.sql.postgres
new file mode 100644
index 0000000000..f305d9a73a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_push_rules_stream.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE push_rules_stream REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_ratelimit_override.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_ratelimit_override.sql.postgres
new file mode 100644
index 0000000000..f10f359155
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_ratelimit_override.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE ratelimit_override REPLICA IDENTITY USING INDEX ratelimit_override_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_graph.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_graph.sql.postgres
new file mode 100644
index 0000000000..954dd92667
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_graph.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE receipts_graph REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_linearized.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_linearized.sql.postgres
new file mode 100644
index 0000000000..302d887531
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_receipts_linearized.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE receipts_linearized REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_received_transactions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_received_transactions.sql.postgres
new file mode 100644
index 0000000000..3b8c227717
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_received_transactions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE received_transactions REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_redactions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_redactions.sql.postgres
new file mode 100644
index 0000000000..ffa3444b95
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_redactions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE redactions REPLICA IDENTITY USING INDEX redactions_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_registration_tokens.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_registration_tokens.sql.postgres
new file mode 100644
index 0000000000..3fdb5bbd54
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_registration_tokens.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE registration_tokens REPLICA IDENTITY USING INDEX registration_tokens_token_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_rejections.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_rejections.sql.postgres
new file mode 100644
index 0000000000..c7a7218578
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_rejections.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE rejections REPLICA IDENTITY USING INDEX rejections_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache.sql.postgres
new file mode 100644
index 0000000000..d0ecfe1a75
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE remote_media_cache REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache_thumbnails.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache_thumbnails.sql.postgres
new file mode 100644
index 0000000000..9d7b63dfb4
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_remote_media_cache_thumbnails.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE remote_media_cache_thumbnails REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_account_data.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_account_data.sql.postgres
new file mode 100644
index 0000000000..36e756f6b1
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_account_data.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_account_data REPLICA IDENTITY USING INDEX room_account_data_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_alias_servers.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_alias_servers.sql.postgres
new file mode 100644
index 0000000000..df550076ac
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_alias_servers.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_alias_servers REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_aliases.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_aliases.sql.postgres
new file mode 100644
index 0000000000..bfe8db5375
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_aliases.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_aliases REPLICA IDENTITY USING INDEX room_aliases_room_alias_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_depth.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_depth.sql.postgres
new file mode 100644
index 0000000000..77c78ee4ab
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_depth.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_depth REPLICA IDENTITY USING INDEX room_depth_room_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_forgetter_stream_pos.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_forgetter_stream_pos.sql.postgres
new file mode 100644
index 0000000000..51de67b549
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_forgetter_stream_pos.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_forgetter_stream_pos REPLICA IDENTITY USING INDEX room_forgetter_stream_pos_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_memberships.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_memberships.sql.postgres
new file mode 100644
index 0000000000..5819409058
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_memberships.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_memberships REPLICA IDENTITY USING INDEX room_memberships_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_earliest_token.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_earliest_token.sql.postgres
new file mode 100644
index 0000000000..bacd9587d2
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_earliest_token.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_stats_earliest_token REPLICA IDENTITY USING INDEX room_stats_earliest_token_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_state.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_state.sql.postgres
new file mode 100644
index 0000000000..a64db05f44
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_stats_state.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_stats_state REPLICA IDENTITY USING INDEX room_stats_state_room;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags.sql.postgres
new file mode 100644
index 0000000000..cc69704751
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_tags REPLICA IDENTITY USING INDEX room_tag_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags_revisions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags_revisions.sql.postgres
new file mode 100644
index 0000000000..d31063277c
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_room_tags_revisions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE room_tags_revisions REPLICA IDENTITY USING INDEX room_tag_revisions_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_server_keys_json.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_server_keys_json.sql.postgres
new file mode 100644
index 0000000000..9c0bfb5623
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_server_keys_json.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE server_keys_json REPLICA IDENTITY USING INDEX server_keys_json_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_server_signature_keys.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_server_signature_keys.sql.postgres
new file mode 100644
index 0000000000..1b3d5e68e5
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_server_signature_keys.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE server_signature_keys REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_sessions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_sessions.sql.postgres
new file mode 100644
index 0000000000..eb8d621795
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_sessions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE sessions REPLICA IDENTITY USING INDEX sessions_session_type_session_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_state_events.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_state_events.sql.postgres
new file mode 100644
index 0000000000..7e23c8a054
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_state_events.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE state_events REPLICA IDENTITY USING INDEX state_events_event_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_stats_incremental_position.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_stats_incremental_position.sql.postgres
new file mode 100644
index 0000000000..a4a700a3a4
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_stats_incremental_position.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE stats_incremental_position REPLICA IDENTITY USING INDEX stats_incremental_position_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_stream_ordering_to_exterm.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_stream_ordering_to_exterm.sql.postgres
new file mode 100644
index 0000000000..a700741896
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_stream_ordering_to_exterm.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE stream_ordering_to_exterm REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_stream_positions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_stream_positions.sql.postgres
new file mode 100644
index 0000000000..83ff1c3825
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_stream_positions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE stream_positions REPLICA IDENTITY USING INDEX stream_positions_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_threads.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_threads.sql.postgres
new file mode 100644
index 0000000000..a3891e4208
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_threads.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE threads REPLICA IDENTITY USING INDEX threads_uniqueness;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_threepid_guest_access_tokens.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_threepid_guest_access_tokens.sql.postgres
new file mode 100644
index 0000000000..df31cf4f1d
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_threepid_guest_access_tokens.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE threepid_guest_access_tokens REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_timeline_gaps.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_timeline_gaps.sql.postgres
new file mode 100644
index 0000000000..8fb41226c1
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_timeline_gaps.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE timeline_gaps REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions.sql.postgres
new file mode 100644
index 0000000000..5d2af97f72
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE ui_auth_sessions REPLICA IDENTITY USING INDEX ui_auth_sessions_session_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_credentials.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_credentials.sql.postgres
new file mode 100644
index 0000000000..efb2359faa
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_credentials.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE ui_auth_sessions_credentials REPLICA IDENTITY USING INDEX ui_auth_sessions_credentials_session_id_stage_type_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_ips.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_ips.sql.postgres
new file mode 100644
index 0000000000..a4b86eaf07
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_ui_auth_sessions_ips.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE ui_auth_sessions_ips REPLICA IDENTITY USING INDEX ui_auth_sessions_ips_session_id_ip_user_agent_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_daily_visits.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_daily_visits.sql.postgres
new file mode 100644
index 0000000000..bb22ec5335
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_daily_visits.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_daily_visits REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory.sql.postgres
new file mode 100644
index 0000000000..947f8c5c0f
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_directory REPLICA IDENTITY USING INDEX user_directory_user_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_search.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_search.sql.postgres
new file mode 100644
index 0000000000..d421779944
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_search.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_directory_search REPLICA IDENTITY USING INDEX user_directory_search_user_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_stream_pos.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_stream_pos.sql.postgres
new file mode 100644
index 0000000000..59201750b0
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_directory_stream_pos.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_directory_stream_pos REPLICA IDENTITY USING INDEX user_directory_stream_pos_lock_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_external_ids.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_external_ids.sql.postgres
new file mode 100644
index 0000000000..219ee16dde
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_external_ids.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_external_ids REPLICA IDENTITY USING INDEX user_external_ids_auth_provider_external_id_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_filters.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_filters.sql.postgres
new file mode 100644
index 0000000000..5d3e0ae475
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_filters.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_filters REPLICA IDENTITY FULL; -- sadly the `CHECK` constraint is not enough here
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_ips.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_ips.sql.postgres
new file mode 100644
index 0000000000..5a1d8770d0
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_ips.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_ips REPLICA IDENTITY USING INDEX user_ips_user_token_ip_unique_index;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_signature_stream.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_signature_stream.sql.postgres
new file mode 100644
index 0000000000..8bc27df00a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_signature_stream.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_signature_stream REPLICA IDENTITY USING INDEX user_signature_stream_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepid_id_server.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepid_id_server.sql.postgres
new file mode 100644
index 0000000000..a0ba8e6773
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepid_id_server.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_threepid_id_server REPLICA IDENTITY USING INDEX user_threepid_id_server_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepids.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepids.sql.postgres
new file mode 100644
index 0000000000..9c70c9011e
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_user_threepids.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE user_threepids REPLICA IDENTITY USING INDEX medium_address;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_users.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_users.sql.postgres
new file mode 100644
index 0000000000..725e6cdc76
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_users.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE users REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_users_in_public_rooms.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_users_in_public_rooms.sql.postgres
new file mode 100644
index 0000000000..86988a5550
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_users_in_public_rooms.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE users_in_public_rooms REPLICA IDENTITY USING INDEX users_in_public_rooms_u_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_users_pending_deactivation.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_users_pending_deactivation.sql.postgres
new file mode 100644
index 0000000000..7e72946d14
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_users_pending_deactivation.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE users_pending_deactivation REPLICA IDENTITY FULL;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_users_who_share_private_rooms.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_users_who_share_private_rooms.sql.postgres
new file mode 100644
index 0000000000..6c7213920a
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_users_who_share_private_rooms.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE users_who_share_private_rooms REPLICA IDENTITY USING INDEX users_who_share_private_rooms_u_idx;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_worker_locks.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_locks.sql.postgres
new file mode 100644
index 0000000000..1bba45e05c
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_locks.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE worker_locks REPLICA IDENTITY USING INDEX worker_locks_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks.sql.postgres
new file mode 100644
index 0000000000..b9d35eb4f6
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE worker_read_write_locks REPLICA IDENTITY USING INDEX worker_read_write_locks_key;
diff --git a/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks_mode.sql.postgres b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks_mode.sql.postgres
new file mode 100644
index 0000000000..5871c98dee
--- /dev/null
+++ b/synapse/storage/schema/main/delta/83/10_replica_identity_worker_read_write_locks_mode.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE worker_read_write_locks_mode REPLICA IDENTITY USING INDEX worker_read_write_locks_mode_key;
diff --git a/synapse/storage/schema/state/delta/83/10_replica_identity_state_group_edges.sql.postgres b/synapse/storage/schema/state/delta/83/10_replica_identity_state_group_edges.sql.postgres
new file mode 100644
index 0000000000..aa8fc2514c
--- /dev/null
+++ b/synapse/storage/schema/state/delta/83/10_replica_identity_state_group_edges.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE state_group_edges REPLICA IDENTITY USING INDEX state_group_edges_unique_idx;
diff --git a/synapse/storage/schema/state/delta/83/10_replica_identity_state_groups_state.sql.postgres b/synapse/storage/schema/state/delta/83/10_replica_identity_state_groups_state.sql.postgres
new file mode 100644
index 0000000000..4386031977
--- /dev/null
+++ b/synapse/storage/schema/state/delta/83/10_replica_identity_state_groups_state.sql.postgres
@@ -0,0 +1 @@
+ALTER TABLE state_groups_state REPLICA IDENTITY FULL;
diff --git a/tests/rest/admin/test_server_notice.py b/tests/rest/admin/test_server_notice.py
index dfd14f5751..2398bc503a 100644
--- a/tests/rest/admin/test_server_notice.py
+++ b/tests/rest/admin/test_server_notice.py
@@ -477,6 +477,33 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
         # second room has new ID
         self.assertNotEqual(first_room_id, second_room_id)
 
+    @override_config(
+        {"server_notices": {"system_mxid_localpart": "notices", "auto_join": True}}
+    )
+    def test_auto_join(self) -> None:
+        """
+        Tests that the user get automatically joined to the notice room
+        when `auto_join` setting is used.
+        """
+        # user has no room memberships
+        self._check_invite_and_join_status(self.other_user, 0, 0)
+
+        # send server notice
+        server_notice_request_content = {
+            "user_id": self.other_user,
+            "content": {"msgtype": "m.text", "body": "test msg one"},
+        }
+
+        self.make_request(
+            "POST",
+            self.url,
+            access_token=self.admin_user_tok,
+            content=server_notice_request_content,
+        )
+
+        # user has joined the room
+        self._check_invite_and_join_status(self.other_user, 0, 1)
+
     @override_config({"server_notices": {"system_mxid_localpart": "notices"}})
     def test_update_notice_user_name_when_changed(self) -> None:
         """
diff --git a/tests/rest/client/test_profile.py b/tests/rest/client/test_profile.py
index 8f923fd40f..eb0fa00bb3 100644
--- a/tests/rest/client/test_profile.py
+++ b/tests/rest/client/test_profile.py
@@ -312,6 +312,166 @@ class ProfileTestCase(unittest.HomeserverTestCase):
         )
         self.assertEqual(channel.code, 200, channel.result)
 
+    @unittest.override_config(
+        {"experimental_features": {"msc4069_profile_inhibit_propagation": True}}
+    )
+    def test_msc4069_inhibit_propagation(self) -> None:
+        """Tests to ensure profile update propagation can be inhibited."""
+        for prop in ["avatar_url", "displayname"]:
+            room_id = self.helper.create_room_as(tok=self.owner_tok)
+
+            channel = self.make_request(
+                "PUT",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                content={"membership": "join", prop: "mxc://my.server/existing"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            channel = self.make_request(
+                "PUT",
+                f"/profile/{self.owner}/{prop}?org.matrix.msc4069.propagate=false",
+                content={prop: "http://my.server/pic.gif"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            res = (
+                self._get_avatar_url()
+                if prop == "avatar_url"
+                else self._get_displayname()
+            )
+            self.assertEqual(res, "http://my.server/pic.gif")
+
+            channel = self.make_request(
+                "GET",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+            self.assertEqual(channel.json_body.get(prop), "mxc://my.server/existing")
+
+    def test_msc4069_inhibit_propagation_disabled(self) -> None:
+        """Tests to ensure profile update propagation inhibit flags are ignored when the
+        experimental flag is not enabled.
+        """
+        for prop in ["avatar_url", "displayname"]:
+            room_id = self.helper.create_room_as(tok=self.owner_tok)
+
+            channel = self.make_request(
+                "PUT",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                content={"membership": "join", prop: "mxc://my.server/existing"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            channel = self.make_request(
+                "PUT",
+                f"/profile/{self.owner}/{prop}?org.matrix.msc4069.propagate=false",
+                content={prop: "http://my.server/pic.gif"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            res = (
+                self._get_avatar_url()
+                if prop == "avatar_url"
+                else self._get_displayname()
+            )
+            self.assertEqual(res, "http://my.server/pic.gif")
+
+            channel = self.make_request(
+                "GET",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            # The ?propagate=false should be ignored by the server because the config flag
+            # isn't enabled.
+            self.assertEqual(channel.json_body.get(prop), "http://my.server/pic.gif")
+
+    def test_msc4069_inhibit_propagation_default(self) -> None:
+        """Tests to ensure profile update propagation happens by default."""
+        for prop in ["avatar_url", "displayname"]:
+            room_id = self.helper.create_room_as(tok=self.owner_tok)
+
+            channel = self.make_request(
+                "PUT",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                content={"membership": "join", prop: "mxc://my.server/existing"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            channel = self.make_request(
+                "PUT",
+                f"/profile/{self.owner}/{prop}",
+                content={prop: "http://my.server/pic.gif"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            res = (
+                self._get_avatar_url()
+                if prop == "avatar_url"
+                else self._get_displayname()
+            )
+            self.assertEqual(res, "http://my.server/pic.gif")
+
+            channel = self.make_request(
+                "GET",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            # The ?propagate=false should be ignored by the server because the config flag
+            # isn't enabled.
+            self.assertEqual(channel.json_body.get(prop), "http://my.server/pic.gif")
+
+    @unittest.override_config(
+        {"experimental_features": {"msc4069_profile_inhibit_propagation": True}}
+    )
+    def test_msc4069_inhibit_propagation_like_default(self) -> None:
+        """Tests to ensure clients can request explicit profile propagation."""
+        for prop in ["avatar_url", "displayname"]:
+            room_id = self.helper.create_room_as(tok=self.owner_tok)
+
+            channel = self.make_request(
+                "PUT",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                content={"membership": "join", prop: "mxc://my.server/existing"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            channel = self.make_request(
+                "PUT",
+                f"/profile/{self.owner}/{prop}?org.matrix.msc4069.propagate=true",
+                content={prop: "http://my.server/pic.gif"},
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            res = (
+                self._get_avatar_url()
+                if prop == "avatar_url"
+                else self._get_displayname()
+            )
+            self.assertEqual(res, "http://my.server/pic.gif")
+
+            channel = self.make_request(
+                "GET",
+                f"/rooms/{room_id}/state/m.room.member/{self.owner}",
+                access_token=self.owner_tok,
+            )
+            self.assertEqual(channel.code, 200, channel.result)
+
+            # The client requested ?propagate=true, so it should have happened.
+            self.assertEqual(channel.json_body.get(prop), "http://my.server/pic.gif")
+
     def _setup_local_files(self, names_and_props: Dict[str, Dict[str, Any]]) -> None:
         """Stores metadata about files in the database.
 
diff --git a/tests/rest/client/test_upgrade_room.py b/tests/rest/client/test_upgrade_room.py
index 0b4c691318..28f772261b 100644
--- a/tests/rest/client/test_upgrade_room.py
+++ b/tests/rest/client/test_upgrade_room.py
@@ -246,6 +246,34 @@ class UpgradeRoomTest(unittest.HomeserverTestCase):
         # We should now have an integer power level.
         self.assertEqual(new_power_levels["users"][self.creator], 100, new_power_levels)
 
+    def test_events_field_missing(self) -> None:
+        """Regression test for https://github.com/matrix-org/synapse/issues/16715."""
+        # Create a new room.
+        room_id = self.helper.create_room_as(
+            self.creator, tok=self.creator_token, room_version="10"
+        )
+        self.helper.join(room_id, self.other, tok=self.other_token)
+
+        # Retrieve the room's current power levels.
+        power_levels = self.helper.get_state(
+            room_id,
+            "m.room.power_levels",
+            tok=self.creator_token,
+        )
+
+        # Remove the events field and re-set the power levels.
+        del power_levels["events"]
+        self.helper.send_state(
+            room_id,
+            "m.room.power_levels",
+            body=power_levels,
+            tok=self.creator_token,
+        )
+
+        # Upgrade the room. Check the homeserver reports success.
+        channel = self._upgrade_room(room_id=room_id)
+        self.assertEqual(200, channel.code, channel.result)
+
     def test_space(self) -> None:
         """Test upgrading a space."""
 
diff --git a/tests/storage/test_database.py b/tests/storage/test_database.py
index 4d0ebb550d..aa8c76f187 100644
--- a/tests/storage/test_database.py
+++ b/tests/storage/test_database.py
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Callable, Tuple
+from typing import Callable, List, Tuple
 from unittest.mock import Mock, call
 
 from twisted.internet import defer
@@ -29,6 +29,7 @@ from synapse.storage.database import (
 from synapse.util import Clock
 
 from tests import unittest
+from tests.utils import USE_POSTGRES_FOR_TESTS
 
 
 class TupleComparisonClauseTestCase(unittest.TestCase):
@@ -279,3 +280,85 @@ class CancellationTestCase(unittest.HomeserverTestCase):
             ]
         )
         self.assertEqual(exception_callback.call_count, 6)  # no additional calls
+
+
+class PostgresReplicaIdentityTestCase(unittest.HomeserverTestCase):
+    if not USE_POSTGRES_FOR_TESTS:
+        skip = "Requires Postgres"
+
+    def prepare(
+        self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer
+    ) -> None:
+        self.db_pools = homeserver.get_datastores().databases
+
+    def test_all_tables_have_postgres_replica_identity(self) -> None:
+        """
+        Tests that all tables have a Postgres REPLICA IDENTITY.
+        (See https://github.com/matrix-org/synapse/issues/16224).
+
+        Tables with a PRIMARY KEY have an implied REPLICA IDENTITY and are fine.
+        Other tables need them to be set with `ALTER TABLE`.
+
+        A REPLICA IDENTITY is required for Postgres logical replication to work
+        properly without blocking updates and deletes.
+        """
+
+        sql = """
+            -- Select tables that have no primary key and use the default replica identity rule
+            -- (the default is to use the primary key)
+            WITH tables_no_pkey AS (
+                SELECT tbl.table_schema, tbl.table_name
+                FROM information_schema.tables tbl
+                WHERE table_type = 'BASE TABLE'
+                    AND table_schema not in ('pg_catalog', 'information_schema')
+                    AND NOT EXISTS (
+                        SELECT 1
+                        FROM information_schema.table_constraints tc
+                        WHERE tc.constraint_type = 'PRIMARY KEY'
+                            AND tc.table_schema = tbl.table_schema
+                            AND tc.table_name = tbl.table_name
+                    )
+            )
+            SELECT pg_class.oid::regclass FROM tables_no_pkey INNER JOIN pg_class ON pg_class.oid::regclass = table_name::regclass
+            WHERE relreplident = 'd'
+
+            UNION
+
+            -- Also select tables that use an index as a replica identity
+            -- but where the index doesn't exist
+            -- (e.g. it could have been deleted)
+            SELECT pg_class.oid::regclass
+                FROM information_schema.tables tbl
+                INNER JOIN pg_class ON pg_class.oid::regclass = table_name::regclass
+                WHERE table_type = 'BASE TABLE'
+                    AND table_schema not in ('pg_catalog', 'information_schema')
+
+                    -- 'i' means an index is used as the replica identity
+                    AND relreplident = 'i'
+
+                    -- look for indices that are marked as the replica identity
+                    AND NOT EXISTS (
+                        SELECT indexrelid::regclass
+                        FROM pg_index
+                        WHERE indrelid = pg_class.oid::regclass AND indisreplident
+                    )
+        """
+
+        def _list_tables_with_missing_replica_identities_txn(
+            txn: LoggingTransaction,
+        ) -> List[str]:
+            txn.execute(sql)
+            return [table_name for table_name, in txn]
+
+        for pool in self.db_pools:
+            missing = self.get_success(
+                pool.runInteraction(
+                    "test_list_missing_replica_identities",
+                    _list_tables_with_missing_replica_identities_txn,
+                )
+            )
+            self.assertEqual(
+                len(missing),
+                0,
+                f"The following tables in the {pool.name()!r} database are missing REPLICA IDENTITIES: {missing!r}.",
+            )