Use C collation for Postgres to appease Synapse

This commit is contained in:
Slavi Pantaleev 2020-01-21 00:12:49 +02:00
parent f9d21befdf
commit 9d3d538a2d
3 changed files with 27 additions and 2 deletions

View file

@ -1,3 +1,20 @@
# 2020-01-21
## Postgres collation changes (action required!)
By default, we've been using a UTF-8 collation for Postgres. This is known to cause Synapse some troubles (see the [relevant issue](https://github.com/matrix-org/synapse/issues/6722)) on systems that use [glibc](https://www.gnu.org/software/libc/). We run Postgres in an [Alpine Linux](https://alpinelinux.org/) container (which uses [musl](https://www.musl-libc.org/), and not glibc), so our users are likely not affected by the index corruption problem observed by others.
Still, we might become affected in the future. In any case, it's imminent that Synapse will complain about databases which do not use a C collation.
To avoid future problems, we recommend that you run the following command:
```
ansible-playbook -i inventory/hosts setup.yml --tags=upgrade-postgres --extra-vars='{"postgres_force_upgrade": true}'
```
It forces a [Postgres database upgrade](docs/maintenance-postgres.md#upgrading-postgresql), which would recreate your Postgres database using the proper (`C`) collation. If you are low on disk space, or run into trouble, refer to the Postgres database upgrade documentation page.
# 2020-01-14 # 2020-01-14
## Added support for Appservice Webhooks ## Added support for Appservice Webhooks

View file

@ -20,6 +20,11 @@
postgres_start_wait_time: 15 postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''" when: "postgres_start_wait_time|default('') == ''"
- name: Set postgres_force_upgrade, if not provided
set_fact:
postgres_force_upgrade: false
when: "postgres_force_upgrade|default('') == ''"
- name: Fail, if trying to upgrade external Postgres database - name: Fail, if trying to upgrade external Postgres database
fail: fail:
msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade." msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade."
@ -45,7 +50,7 @@
- name: Abort, if already at latest Postgres version - name: Abort, if already at latest Postgres version
fail: fail:
msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do" msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do"
when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest" when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest and not postgres_force_upgrade"
- debug: - debug:
msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}" msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}"

View file

@ -2,3 +2,6 @@
POSTGRES_USER={{ matrix_postgres_connection_username }} POSTGRES_USER={{ matrix_postgres_connection_username }}
POSTGRES_PASSWORD={{ matrix_postgres_connection_password }} POSTGRES_PASSWORD={{ matrix_postgres_connection_password }}
POSTGRES_DB={{ matrix_postgres_db_name }} POSTGRES_DB={{ matrix_postgres_db_name }}
# Synapse refuses to run if collation is not C.
# See https://github.com/matrix-org/synapse/issues/6722
POSTGRES_INITDB_ARGS=--lc-collate C --lc-ctype C --encoding UTF8