From 65e6e80100b80acf1154636f696e580cda7030c6 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Thu, 25 Jun 2026 20:50:49 +0100 Subject: [PATCH 1/5] Postgres CI: disable crash-safety features for speed --- .github/workflows/tests.yml | 12 ++++++++++-- docker/complement/conf/postgres.supervisord.conf | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6ecdd88815e..9ccb4226be8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -383,13 +383,21 @@ jobs: if: ${{ matrix.job.postgres-version }} # 1. Mount postgres data files onto a tmpfs in-memory filesystem to reduce overhead of docker's overlayfs layer. # 2. Expose the unix socket for postgres. This removes latency of using docker-proxy for connections. + # 3. We disable crash-safety features for speed: fsync, synchronous commits, full-page writes. + # Note: synchronous commits are enabled/disabled at runtime by Synapse, so there is also + # code in `tests/server.py` to configure this as off. run: | docker run -d -p 5432:5432 \ - --tmpfs /var/lib/postgres:rw,size=6144m \ + --tmpfs /var/lib/postgresql:rw,size=6144m \ --mount 'type=bind,src=/var/run/postgresql,dst=/var/run/postgresql' \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \ - postgres:${{ matrix.job.postgres-version }} + postgres:${{ matrix.job.postgres-version }} \ + -c fsync=off \ + -c synchronous_commit=off \ + -c full_page_writes=off \ + -c wal_level=minimal \ + -c max_wal_senders=0 - name: Install Rust uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # master diff --git a/docker/complement/conf/postgres.supervisord.conf b/docker/complement/conf/postgres.supervisord.conf index 657845dfdbc..e48921236fc 100644 --- a/docker/complement/conf/postgres.supervisord.conf +++ b/docker/complement/conf/postgres.supervisord.conf @@ -1,5 +1,11 @@ [program:postgres] +# Disable crash-safety features for speed: fsync, synchronous commit, full page writes command=/usr/local/bin/prefix-log gosu postgres postgres + -c fsync=off + -c synchronous_commit=off + -c full_page_writes=off + -c wal_level=minimal + -c max_wal_senders=0 # Only start if START_POSTGRES=true autostart=%(ENV_START_POSTGRES)s From d900dcf20335bfb19d6a2898341440fb7666d527 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Thu, 25 Jun 2026 20:54:15 +0100 Subject: [PATCH 2/5] Newsfile Signed-off-by: Olivier 'reivilibre --- changelog.d/19880.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/19880.misc diff --git a/changelog.d/19880.misc b/changelog.d/19880.misc new file mode 100644 index 00000000000..c7ce7824bcf --- /dev/null +++ b/changelog.d/19880.misc @@ -0,0 +1 @@ +Disable Postgres crash-safety features in CI for speed. \ No newline at end of file From 829ca08211d0fa8ca716107be3a89f6ee302db74 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Fri, 26 Jun 2026 11:45:02 +0100 Subject: [PATCH 3/5] Fix tmpfs mount for predictability --- .github/workflows/tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9ccb4226be8..45ac29a0f39 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -382,14 +382,17 @@ jobs: - name: Set up PostgreSQL ${{ matrix.job.postgres-version }} if: ${{ matrix.job.postgres-version }} # 1. Mount postgres data files onto a tmpfs in-memory filesystem to reduce overhead of docker's overlayfs layer. + # Use a custom path to ensure stability (it will change across versions, + # see https://github.com/docker-library/postgres/blob/be0b7ac960bb393b00a31938b6d878397f482759/Dockerfile-debian.template#L188) # 2. Expose the unix socket for postgres. This removes latency of using docker-proxy for connections. # 3. We disable crash-safety features for speed: fsync, synchronous commits, full-page writes. # Note: synchronous commits are enabled/disabled at runtime by Synapse, so there is also # code in `tests/server.py` to configure this as off. run: | docker run -d -p 5432:5432 \ - --tmpfs /var/lib/postgresql:rw,size=6144m \ + --tmpfs /pgdata:rw,size=6144m \ --mount 'type=bind,src=/var/run/postgresql,dst=/var/run/postgresql' \ + -e PGDATA=/pgdata \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \ postgres:${{ matrix.job.postgres-version }} \ From 6042ed08c66f6dff0dc3568769781b490ba4bf66 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 29 Jun 2026 18:53:04 +0100 Subject: [PATCH 4/5] Trial: disable synchronous commit --- tests/server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/server.py b/tests/server.py index ce5eaad63da..bc6ce40a733 100644 --- a/tests/server.py +++ b/tests/server.py @@ -1134,6 +1134,11 @@ def setup_test_homeserver( "port": POSTGRES_PORT, "cp_min": 1, "cp_max": 5, + # Tolerate data loss for testing speedup. + # https://postgresqlco.nf/doc/en/param/synchronous_commit/ + # (Mechanically: means we ask Postgres not to wait to flush data to disk before + # telling us transactions are committed.) + "synchronous_commit": False, }, } else: From 2755d61a870f19db2a43f817f4eed184421251f2 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 29 Jun 2026 18:59:09 +0100 Subject: [PATCH 5/5] Actually wire up disabling synchronous commit in Complement, too --- docker/complement/conf/postgres.supervisord.conf | 2 ++ docker/complement/conf/start_for_complement.sh | 3 +++ docker/conf/homeserver.yaml | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/docker/complement/conf/postgres.supervisord.conf b/docker/complement/conf/postgres.supervisord.conf index e48921236fc..16f9c1e881a 100644 --- a/docker/complement/conf/postgres.supervisord.conf +++ b/docker/complement/conf/postgres.supervisord.conf @@ -1,5 +1,7 @@ [program:postgres] # Disable crash-safety features for speed: fsync, synchronous commit, full page writes +# Note: synchronous commits are enabled/disabled at runtime by Synapse, so there is also +# an env set in `start_for_complement.sh` to configure this as off. command=/usr/local/bin/prefix-log gosu postgres postgres -c fsync=off -c synchronous_commit=off diff --git a/docker/complement/conf/start_for_complement.sh b/docker/complement/conf/start_for_complement.sh index e0d30abed36..cdcd47a88a4 100755 --- a/docker/complement/conf/start_for_complement.sh +++ b/docker/complement/conf/start_for_complement.sh @@ -27,6 +27,9 @@ case "$SYNAPSE_COMPLEMENT_DATABASE" in export POSTGRES_USER=postgres export POSTGRES_HOST=localhost + # Disable synchronous commit for potential performance gains + export __PRIVATE_SYNAPSE_DISABLE_SYNCHRONOUS_COMMIT=1 + # configure supervisord to start postgres export START_POSTGRES=true ;; diff --git a/docker/conf/homeserver.yaml b/docker/conf/homeserver.yaml index e2e1338673d..16224b9e090 100644 --- a/docker/conf/homeserver.yaml +++ b/docker/conf/homeserver.yaml @@ -71,6 +71,10 @@ database: user: "{{ POSTGRES_USER or "synapse" }}" password: "{{ POSTGRES_PASSWORD }}" database: "{{ POSTGRES_DB or "synapse" }}" +{# Used by Complement. Not documented as a stable option. CAUSES RISK OF DATA LOSS. #} +{% if __PRIVATE_SYNAPSE_DISABLE_SYNCHRONOUS_COMMIT %} + synchronous_commit: false +{% endif %} {% if not SYNAPSE_USE_UNIX_SOCKET %} {# Synapse will use a default unix socket for Postgres when host/port is not specified (behavior from `psycopg2`). #} host: "{{ POSTGRES_HOST or "db" }}"