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..e21c7446 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 <