From c9e6cbeb9fa4c0c6e046d075711188415ef268fc 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 | 10 +++++++++- test/run_test | 17 +++++++++++++++++ 3 files changed, 33 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..cbe05ebb 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 UTF-8 + +**`POSTGRESQL_LOCALE`** + Database locale. Default to en_EN 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..6299b512 100644 --- a/src/root/usr/share/container-scripts/postgresql/common.sh +++ b/src/root/usr/share/container-scripts/postgresql/common.sh @@ -223,7 +223,15 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then 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 <