Migrate Matrix Synapse from SQLite to PostgreSQL

SQLite over NFS caused database corruption (malformed disk image).
Recovered the DB, migrated data to PostgreSQL via synapse_port_db,
and updated the deployment to use psycopg2 with an init container.

Database: matrix on postgresql.dbaas.svc.cluster.local
Scaled replicas from 0 to 1.
This commit is contained in:
Viktor Barzin 2026-03-13 23:21:59 +00:00 committed by Viktor Barzin
parent 1db9c65cd6
commit ed7603d7e6

View file

@ -1,5 +1,5 @@
variable "tls_secret_name" {
type = string
type = string
sensitive = true
}
variable "nfs_server" { type = string }
@ -39,7 +39,7 @@ resource "kubernetes_deployment" "matrix" {
}
}
spec {
replicas = 0
replicas = 1
selector {
match_labels = {
app = "matrix"
@ -52,6 +52,15 @@ resource "kubernetes_deployment" "matrix" {
}
}
spec {
init_container {
name = "install-psycopg2"
image = "matrixdotorg/synapse:latest"
command = ["/bin/sh", "-c", "pip install --target=/extra-packages psycopg2-binary 2>/dev/null"]
volume_mount {
name = "extra-packages"
mount_path = "/extra-packages"
}
}
container {
image = "matrixdotorg/synapse:latest"
name = "matrix"
@ -66,10 +75,18 @@ resource "kubernetes_deployment" "matrix" {
name = "SYNAPSE_REPORT_STATS"
value = "yes"
}
env {
name = "PYTHONPATH"
value = "/extra-packages"
}
volume_mount {
name = "data"
mount_path = "/data"
}
volume_mount {
name = "extra-packages"
mount_path = "/extra-packages"
}
}
volume {
name = "data"
@ -77,6 +94,10 @@ resource "kubernetes_deployment" "matrix" {
claim_name = module.nfs_data.claim_name
}
}
volume {
name = "extra-packages"
empty_dir {}
}
}
}
}