Skip to content
Snippets Groups Projects
Verified Commit cee7ae18 authored by Jan Alexander Steffens (heftig)'s avatar Jan Alexander Steffens (heftig)
Browse files

postgres: Allow specifying locale per-machine

Synapse needs the database to be in C locale. Since v1.56.0, it refuses
to start when this is not the case, see [upgrade.md][1].

Replace `en_US.UTF-8` with a variable where present and adapt the
`upgrade_pg.sh` script to copy the locale from the old cluster.

[1]: https://github.com/matrix-org/synapse/blob/c1482a352acd35055db93f5d0b5de1bec8974fa0/docs/upgrade.md#upgrading-to-v1560
parent 2c681a35
No related branches found
No related tags found
1 merge request!558postgres: Allow specifying locale per-machine
Pipeline #17577 passed
......@@ -17,6 +17,7 @@
postgres_work_mem: 64MB
postgres_maintenance_work_mem: 256MB
postgres_effective_cache_size: 4GB
postgres_locale: C
- { role: postfix_null }
- { role: matrix }
- { role: fail2ban }
......
......@@ -21,3 +21,5 @@ postgres_ssl_hosts4: []
postgres_ssl_hosts6: []
postgres_backup_dir: '/root/backup-postgres'
postgres_locale: 'en_US.UTF-8'
......@@ -30,6 +30,9 @@ if [[ -d /var/lib/postgres/data-$FROM_VERSION ]]; then
exit 3
fi
## Copy the locale from the old cluster
locale=$(sudo -u postgres psql -A -t --dbname=template1 -c 'SHOW lc_collate;')
# mask postgresql.service to make sure that other services with
# Wants=postgresql.service and Restart=on-failure will not start
# it again during the upgrade
......@@ -42,7 +45,7 @@ chown postgres:postgres /var/lib/postgres/
su - postgres -c "mv /var/lib/postgres/data /var/lib/postgres/data-$FROM_VERSION"
su - postgres -c 'mkdir /var/lib/postgres/data'
su - postgres -c 'chattr -f +C /var/lib/postgres/data' || :
su - postgres -c 'initdb --locale en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data'
su - postgres -c "initdb --locale=$locale -E UTF8 -D /var/lib/postgres/data"
vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/pg_hba.conf
vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/postgresql.conf
......
......@@ -23,7 +23,7 @@
become: true
become_user: postgres
become_method: su
command: initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
command: initdb --locale={{ postgres_locale }} -E UTF8 -D '/var/lib/postgres/data'
args:
chdir: /var/lib/postgres
creates: /var/lib/postgres/data/postgresql.conf
......
......@@ -691,11 +691,11 @@ timezone = 'UTC'
# encoding
# These settings are initialized by initdb, but they can be changed.
lc_messages = 'en_US.UTF-8' # locale for system error message
lc_messages = '{{ postgres_locale }}' # locale for system error message
# strings
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
lc_numeric = 'en_US.UTF-8' # locale for number formatting
lc_time = 'en_US.UTF-8' # locale for time formatting
lc_monetary = '{{ postgres_locale }}' # locale for monetary formatting
lc_numeric = '{{ postgres_locale }}' # locale for number formatting
lc_time = '{{ postgres_locale }}' # locale for time formatting
# default configuration for text search
default_text_search_config = 'pg_catalog.english'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment