From 8bc325b148d9fed8e193562f64859134da4691fd Mon Sep 17 00:00:00 2001 From: Sovran Contributor Date: Mon, 21 Sep 2026 19:19:48 +0000 Subject: [PATCH] postgresql: drop per-database autovacuum ALTERs (rejected by Postgres) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the previous two commits: the ALTER DATABASE ... SET autovacuum_* commands fail at boot with ERROR: parameter "autovacuum_vacuum_scale_factor" cannot be changed now and take matrix-synapse-db-tune.service (and nextcloud-db-init.service) down with them. Root cause: ALTER DATABASE/ROLE ... SET validates through set_config_option() with an interactive context, and guc.c rejects any PGC_SIGHUP parameter set that way. All autovacuum_* GUCs are SIGHUP-context, so per-database scoping is impossible for them — only USERSET-level parameters (e.g. work_mem, statement_timeout) can be set per-database. Nothing is lost: the same values are already set cluster-wide in configuration.nix, which covers both nextclouddb and matrix-synapse. Remove the ALTERs from nextcloud-db-init and delete the now-purposeless matrix-synapse-db-tune service. --- modules/nextcloud.nix | 10 +++++----- modules/synapse.nix | 29 ----------------------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/modules/nextcloud.nix b/modules/nextcloud.nix index 6b5b599..486e675 100755 --- a/modules/nextcloud.nix +++ b/modules/nextcloud.nix @@ -60,11 +60,11 @@ lib.mkIf config.sovran_systemsOS.services.nextcloud { psql -U postgres -c "CREATE DATABASE nextclouddb WITH OWNER ncusr TEMPLATE template0 LC_COLLATE = 'C' LC_CTYPE = 'C';" fi - # Per-database autovacuum, scoped to nextclouddb only. - # The shared matrix-synapse DB keeps the milder cluster defaults. - # Fixes Nextcloud 35 pg.dead_tuples warning. Idempotent. - psql -U postgres -d nextclouddb -c "ALTER DATABASE nextclouddb SET autovacuum_vacuum_scale_factor = '0.05';" - psql -U postgres -d nextclouddb -c "ALTER DATABASE nextclouddb SET autovacuum_analyze_scale_factor = '0.025';" + # NOTE: autovacuum GUCs are SIGHUP-context, so they cannot be set + # per-database — ALTER DATABASE ... SET rejects them with + # 'parameter "..." cannot be changed now'. They are set + # cluster-wide in configuration.nix instead, which already covers + # both nextclouddb and matrix-synapse. ''; }; diff --git a/modules/synapse.nix b/modules/synapse.nix index 729ffb9..be3a13e 100755 --- a/modules/synapse.nix +++ b/modules/synapse.nix @@ -60,35 +60,6 @@ lib.mkIf config.sovran_systemsOS.services.synapse { ''; }; - # ── Per-database Postgres tuning (matrix-synapse only) ───── - # Mirrors the nextclouddb tuning: Synapse's state and event tables are - # write-heavy and bloat fast under stock autovacuum. Scoped via ALTER - # DATABASE so each DB gets what suits it. Idempotent. - systemd.services.matrix-synapse-db-tune = { - description = "Apply per-database Postgres tuning for Matrix Synapse"; - after = [ "postgresql.service" ]; - requires = [ "postgresql.service" ]; - before = [ "matrix-synapse.service" ]; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - }; - path = [ config.services.postgresql.package pkgs.coreutils ]; - script = '' - set -euo pipefail - # Wait for ensureDatabases to have created the DB on first boot. - for i in $(seq 1 30); do - if psql -U postgres -lqt | cut -d \| -f 1 | grep -qw "matrix-synapse"; then - break - fi - sleep 2 - done - psql -U postgres -d matrix-synapse -c "ALTER DATABASE \"matrix-synapse\" SET autovacuum_vacuum_scale_factor = '0.05';" - psql -U postgres -d matrix-synapse -c "ALTER DATABASE \"matrix-synapse\" SET autovacuum_analyze_scale_factor = '0.025';" - ''; - }; - # ── Generate runtime config from domain files ─────────────── systemd.services.matrix-synapse-runtime-config = { description = "Generate Synapse runtime config from domain files";