diff --git a/playbooks/matrix.archlinux.org.yml b/playbooks/matrix.archlinux.org.yml
index 3c92d9e015a448333d87edfbed479c239511e3e3..98a6fc777d303e08eb5cc8a3ea07ce253ca18290 100644
--- a/playbooks/matrix.archlinux.org.yml
+++ b/playbooks/matrix.archlinux.org.yml
@@ -18,7 +18,6 @@
       postgres_work_mem: 64MB
       postgres_maintenance_work_mem: 256MB
       postgres_effective_cache_size: 4GB
-      postgres_jit: 'off'
     - { role: postfix_null }
     - { role: matrix }
     - { role: fail2ban }
diff --git a/roles/matrix/tasks/main.yml b/roles/matrix/tasks/main.yml
index 16f1a1866c726fc668bb879fd259c3316b1dd5b6..1299d0c687aa91b4a165edad546c5961b030cf3c 100644
--- a/roles/matrix/tasks/main.yml
+++ b/roles/matrix/tasks/main.yml
@@ -77,7 +77,7 @@
 - name: install synapse
   pip:
     name:
-      - 'matrix-synapse[postgres,systemd,url_preview,redis,oidc]==1.39.0'
+      - 'matrix-synapse[postgres,systemd,url_preview,redis,oidc]==1.40.0'
     state: latest
     extra_args: '--upgrade-strategy=eager'
     virtualenv: /var/lib/synapse/venv
diff --git a/roles/matrix/templates/homeserver.yaml.j2 b/roles/matrix/templates/homeserver.yaml.j2
index e5c5acfc73c9352948a5cd2fba60cdf34175822b..dec61af1b842615c58b34bfcad7bedfaa219107e 100644
--- a/roles/matrix/templates/homeserver.yaml.j2
+++ b/roles/matrix/templates/homeserver.yaml.j2
@@ -731,6 +731,9 @@ caches:
 # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
 # 'psycopg2' (for PostgreSQL).
 #
+# 'txn_limit' gives the maximum number of transactions to run per connection
+# before reconnecting. Defaults to 0, which means no limit.
+#
 # 'args' gives options which are passed through to the database engine,
 # except for options starting 'cp_', which are used to configure the Twisted
 # connection pool. For a reference to valid arguments, see:
@@ -751,6 +754,7 @@ caches:
 #
 #database:
 #  name: psycopg2
+#  txn_limit: 10000
 #  args:
 #    user: synapse_user
 #    password: secretpassword
@@ -765,6 +769,7 @@ caches:
 #
 database:
   name: psycopg2
+  txn_limit: 10000
   args:
     dbname: synapse
     user: synapse