diff --git a/deployment/Compose/compose/compose.yaml b/deployment/Compose/compose/compose.yaml index a516b67aca..d3e96e6258 100644 --- a/deployment/Compose/compose/compose.yaml +++ b/deployment/Compose/compose/compose.yaml @@ -39,6 +39,11 @@ services: volumes: # Mounts the container's internal data directory to a named volume - ${SYS_DATA_DIR}/postgres:/var/lib/postgresql + # Mounts initialization scripts to refresh collations on container restart + - ./setup/init-db:/docker-entrypoint-initdb.d + # Custom entrypoint wrapper to execute init scripts on restart, not just init + - ./setup/docker-entrypoint.sh:/usr/local/bin/custom-entrypoint.sh + entrypoint: ["/usr/local/bin/custom-entrypoint.sh"] environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} diff --git a/deployment/Compose/compose/setup/docker-entrypoint.sh b/deployment/Compose/compose/setup/docker-entrypoint.sh new file mode 100644 index 0000000000..9ef42c53f0 --- /dev/null +++ b/deployment/Compose/compose/setup/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +# Custom entrypoint wrapper to run collation refresh before standard postgres entrypoint +# This ensures the refresh runs on container restart, not just initial setup + +# Run our custom initialization scripts +if [ -f /var/lib/postgresql/data/PG_VERSION ]; then + echo "Running custom initialization tasks..." + for script in /docker-entrypoint-initdb.d/*; do + if [ -f "$script" ] && [ -x "$script" ] && [[ "$script" == *.sh ]]; then + echo "Running $script" + "$script" + fi + done +fi + +# Invoke the original postgres entrypoint +exec /usr/local/bin/docker-entrypoint.sh "$@" diff --git a/deployment/Compose/compose/setup/init-db/01-refresh-collations.sh b/deployment/Compose/compose/setup/init-db/01-refresh-collations.sh new file mode 100644 index 0000000000..d1be8fb837 --- /dev/null +++ b/deployment/Compose/compose/setup/init-db/01-refresh-collations.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# Refresh collation versions for all non-template databases +# This fixes collation mismatches when glibc library is updated during PostgreSQL minor version upgrades +# Only run if not a new init (i.e., on container restart/upgrade) +if [ -f /var/lib/postgresql/data/PG_VERSION ]; then + echo "Checking and refreshing collation versions..." + + # Get list of databases that need collation refresh + psql -d postgres -t -c "SELECT datname FROM pg_database WHERE datname NOT IN ('template0','template1') AND EXISTS (SELECT 1 FROM pg_collation WHERE collversion IS NOT NULL AND collversion <> pg_collation_actual_version(oid))" > /tmp/needs_refresh.txt 2>&1 || { echo "Warning: Could not check collation versions"; true; } + + # Run REFRESH for each DB that needs it + while read -r db; do + # Skip empty lines + if [ -z "$(echo "$db" | xargs)" ]; then + continue + fi + db=$(echo "$db" | xargs) # Trim whitespace + echo "Refreshing collation for database: $db" + psql -d "$db" -c "ALTER DATABASE \"$db\" REFRESH COLLATION VERSION" + done < /tmp/needs_refresh.txt + + rm -f /tmp/needs_refresh.txt +fi