Skip to content

Commit

Permalink
Fix locale issue
Browse files Browse the repository at this point in the history
  • Loading branch information
richturner committed Mar 19, 2024
1 parent 6888547 commit 70a3db6
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions or-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# THIS FILE IS FOR MIGRATION OF EXISTING DB TO TIMESCALEDB IMAGE AS TIMESCALE INIT SCRIPTS AREN'T RUN WHEN DB
# ALREADY EXISTS; IT ALSO DOES AN AUTOMATIC REINDEX OF THE DB WHEN OR_REINDEX_COUNTER CHANGES TO SIMPLIFY MIGRATIONS
# IT ALSO AUTOMATICALLY HANDLES UPGRADING OF DATABASE AND DURING MAJOR VERSION CHANGES
# BASED ON: https://github.com/pgautoupgrade/docker-pgautoupgrade

source /docker-entrypoint.sh
docker_setup_env
Expand Down Expand Up @@ -150,13 +151,39 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
# Return the error handling back to automatically aborting on non-0 exit status
set -e

# If no initdb arguments were passed to us from the environment, then work out something valid ourselves
if [ "x${POSTGRES_INITDB_ARGS}" != "x" ]; then
echo "------------------------------------------------------------------------------"
echo "Using initdb arguments passed in from the environment: ${POSTGRES_INITDB_ARGS}"
echo "------------------------------------------------------------------------------"
else
echo "-------------------------------------------------"
echo "Remove postmaster.pid file from PG data directory"
echo "-------------------------------------------------"
rm -f "${OLD}"/postmaster.pid

echo "------------------------------------"
echo "Determining our own initdb arguments"
echo "------------------------------------"
COLLATE=unset
CTYPE=unset
ENCODING=unset
COLLATE=$(echo 'SHOW LC_COLLATE' | "/usr/lib/postgresql/${DB_VERSION}/bin/postgres" --single -D "${OLD}" "${POSTGRES_DB}" | grep 'lc_collate = "' | cut -d '"' -f 2)
CTYPE=$(echo 'SHOW LC_CTYPE' | "/usr/lib/postgresql/${DB_VERSION}/bin/postgres" --single -D "${OLD}" "${POSTGRES_DB}" | grep 'lc_ctype = "' | cut -d '"' -f 2)
ENCODING=$(echo 'SHOW SERVER_ENCODING' | "/usr/lib/postgresql/${DB_VERSION}/bin/postgres" --single -D "${OLD}" "${POSTGRES_DB}" | grep 'server_encoding = "' | cut -d '"' -f 2)
POSTGRES_INITDB_ARGS="--locale=${COLLATE} --lc-collate=${COLLATE} --lc-ctype=${CTYPE} --encoding=${ENCODING}"
echo "---------------------------------------------------------------"
echo "The initdb arguments we determined are: ${POSTGRES_INITDB_ARGS}"
echo "---------------------------------------------------------------"
fi

# Initialise the new PostgreSQL database directory
echo "--------------------------------------------------------------------------------------------------------------------"
echo "Initialising new database directory"
echo "Old database using collation settings: '${POSTGRES_INITDB_ARGS}'. Initialising new database with those settings too"
echo "--------------------------------------------------------------------------------------------------------------------"
initdb -D $PGDATA/new
initdb --username="${POSTGRES_USER}" ${POSTGRES_INITDB_ARGS} ${PGDATA}/new/
echo "------------------------------------"
echo "New database directory initialisation complete"
echo "New database initialisation complete"
echo "------------------------------------"

# Change into the PostgreSQL database directory, to avoid a pg_upgrade error about write permissions
Expand Down

0 comments on commit 70a3db6

Please sign in to comment.