From 541e601f0669c137f30c94a55869a37ea7f1d7dd Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Thu, 22 Jul 2021 21:14:02 +0200 Subject: [PATCH] Add support for locale and encoding, fix #406 --- .../container-scripts/postgresql/README.md | 7 +++++++ .../container-scripts/postgresql/common.sh | 4 +++- test/run_test | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/root/usr/share/container-scripts/postgresql/README.md b/src/root/usr/share/container-scripts/postgresql/README.md index bc01aa9f..9c1a3739 100644 --- a/src/root/usr/share/container-scripts/postgresql/README.md +++ b/src/root/usr/share/container-scripts/postgresql/README.md @@ -74,6 +74,13 @@ initialization by passing `-e VAR=VALUE` to the Docker run command. **`POSTGRESQL_ADMIN_PASSWORD`** Password for the `postgres` admin account (optional) +The following environment variables are optional, and only used when the database is initialzed + +**`POSTGRESQL_ENCODING`** + Database encoding. Default to utf8 + +**`POSTGRESQL_LOCALE`** + Database locale. Default to en_US Alternatively, the following options are related to migration scenario: diff --git a/src/root/usr/share/container-scripts/postgresql/common.sh b/src/root/usr/share/container-scripts/postgresql/common.sh index a8592ffe..7f8cb7d2 100644 --- a/src/root/usr/share/container-scripts/postgresql/common.sh +++ b/src/root/usr/share/container-scripts/postgresql/common.sh @@ -190,7 +190,9 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/{{ spec.version }}/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-utf8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + LANG=${LANG:-$LOCALE.$ENCODING} "$@" } function initialize_database() { diff --git a/test/run_test b/test/run_test index 14860eae..61bfc1b5 100755 --- a/test/run_test +++ b/test/run_test @@ -29,6 +29,7 @@ run_s2i_enable_ssl_test run_upgrade_test run_migration_test run_pgaudit_test +run_locales_test " test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0 @@ -898,6 +899,22 @@ EOSQL" grep -E 'AUDIT: SESSION,.*,.*,READ,SELECT,,,SELECT' "${data_dir}"/userdata/log/postgresql-*.log } +function run_locales_test() { + local name=pg-test-locales + DOCKER_ARGS="-e POSTGRESQL_ENCODING=ISO_8859_6 -e POSTGRESQL_LOCALE=C" create_container $name + wait_ready "$name" + + docker exec -i $(get_cid "$name") bash -c "psql <