Skip to content

Commit c84fed7

Browse files
authored
Merge pull request #92 from Obmondo/mattermost-update
docs(mattermost-operator): Update Readme with portable post-restore DB fix
2 parents 3f16856 + ea3d847 commit c84fed7

2 files changed

Lines changed: 23 additions & 29 deletions

File tree

argocd-helm-charts/kubeaid-addons/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ global:
8080
instanceName: ""
8181

8282
# -- Number of PostgreSQL instances in the cluster
83-
instance: 1
83+
instances: 1
8484

8585
# -- Primary database name created during initdb
8686
database: app

argocd-helm-charts/mattermost-operator/Readme.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,28 @@ This guide outlines the steps to restore a Mattermost instance or migrate it to
4343
```sh
4444
psql -h 172.20.36.240 -p 5432 -d mattermost -U mattermost < <backupfile>.sql
4545
```
46-
Note:
47-
If you are using Mattermost version 10.11.4, the database connection string (DB_CONNECTION_STRING)
48-
is stored inside the database configuration.
49-
After restoring, you must update it with the new PostgreSQL credentials.
50-
51-
```sh
52-
# Connect to PostgreSQL
53-
psql -h 172.20.36.240 -p 5432 -d mattermost -U mattermost
54-
55-
# Fetch the current connection string
56-
mattermost=> SELECT ("value"::jsonb)->'SqlSettings'->>'DataSource' AS "DataSource"
57-
FROM "configurations"
58-
WHERE "active" = true;
59-
60-
# Example output:
61-
# postgres://mattermost:zPWjYqmdpRSb01psy4p1uqTHGmT0WVehvm3nHyuDg7eb9K2WhvJNKBOFjo3USKJK@mattermost-pgsql-rw:5432/mattermost
62-
63-
# Update the connection string using the new credentials
64-
UPDATE configurations
65-
SET "value" = jsonb_set(
66-
"value"::jsonb,
67-
'{SqlSettings,DataSource}',
68-
to_jsonb('postgres://mattermost:P3abi2rHJqGzYaCXyaw9BdDoCAulMnqGUIDdjgA6fQSA21Yc4HNVcjSn6tQ8J3vf@mattermost-pgsql-rw:5432/mattermost'::text),
69-
false
70-
)
71-
WHERE "active" = true;
72-
73-
```
46+
> **Important:** Mattermost (v10.11+) stores the database connection string (`DataSource`)
47+
> inside the `configurations` table in the database itself. After restoring a backup, this
48+
> value will contain the **old** hostname and password from the source cluster, causing
49+
> Mattermost pods to crash with `password authentication failed` or `no such host` errors.
50+
>
51+
> You **must** update it after every restore.
52+
53+
Run this one-liner to automatically fetch the current password from the Kubernetes secret
54+
and patch the `configurations` table:
55+
56+
```sh
57+
DB_PASS=$(kubectl get secret mattermost-operator-pgsql-app -n mattermost-operator -o jsonpath='{.data.password}' | base64 -d) && \
58+
kubectl run psql-fix --rm -i --restart=Never --image=postgres:15 -n mattermost-operator --env="PGPASSWORD=$DB_PASS" -- \
59+
psql -h mattermost-operator-pgsql-rw -U mattermost -d mattermost \
60+
-c "UPDATE configurations SET value = jsonb_set(value::jsonb, '{SqlSettings,DataSource}', to_jsonb('postgres://mattermost:'||'${DB_PASS}'||'@mattermost-operator-pgsql-rw.mattermost-operator:5432/mattermost?sslmode=disable'::text), false) WHERE active = true;"
61+
```
62+
63+
Then restart the Mattermost pods to pick up the corrected config:
64+
65+
```sh
66+
kubectl delete pod -l app=mattermost -n mattermost-operator
67+
```
7468

7569
7. **Copy PVC files to the new S3 bucket to restore file storage.**
7670

0 commit comments

Comments
 (0)