postgresql: drop per-database autovacuum ALTERs (rejected by Postgres)
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.
This commit is contained in:
@@ -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';"
|
psql -U postgres -c "CREATE DATABASE nextclouddb WITH OWNER ncusr TEMPLATE template0 LC_COLLATE = 'C' LC_CTYPE = 'C';"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Per-database autovacuum, scoped to nextclouddb only.
|
# NOTE: autovacuum GUCs are SIGHUP-context, so they cannot be set
|
||||||
# The shared matrix-synapse DB keeps the milder cluster defaults.
|
# per-database — ALTER DATABASE ... SET rejects them with
|
||||||
# Fixes Nextcloud 35 pg.dead_tuples warning. Idempotent.
|
# 'parameter "..." cannot be changed now'. They are set
|
||||||
psql -U postgres -d nextclouddb -c "ALTER DATABASE nextclouddb SET autovacuum_vacuum_scale_factor = '0.05';"
|
# cluster-wide in configuration.nix instead, which already covers
|
||||||
psql -U postgres -d nextclouddb -c "ALTER DATABASE nextclouddb SET autovacuum_analyze_scale_factor = '0.025';"
|
# both nextclouddb and matrix-synapse.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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 ───────────────
|
# ── Generate runtime config from domain files ───────────────
|
||||||
systemd.services.matrix-synapse-runtime-config = {
|
systemd.services.matrix-synapse-runtime-config = {
|
||||||
description = "Generate Synapse runtime config from domain files";
|
description = "Generate Synapse runtime config from domain files";
|
||||||
|
|||||||
Reference in New Issue
Block a user