Skip to content

Commit

Permalink
Add support for locale and encoding, fix sclorg#406
Browse files Browse the repository at this point in the history
  • Loading branch information
mscherer committed Sep 15, 2021
1 parent 83c71ac commit 541e601
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 3 additions & 1 deletion src/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <<EOSQL
SHOW SERVER_ENCODING;
EOSQL" | grep ISO_8859_6

docker exec -i $(get_cid "$name") bash -c "psql <<EOSQL
SHOW SHOW LC_COLLATE;
EOSQL" | grep -vi LC_COLLA | grep C

docker stop "$(get_cid "$name")"
}

function run_all_tests() {
for test_case in $TEST_LIST; do
: "Running test $test_case"
Expand Down

0 comments on commit 541e601

Please sign in to comment.