-
-
Notifications
You must be signed in to change notification settings - Fork 13
fix: Add PostgreSQL collation refresh script for glibc updates #1190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
1261687
ed51014
2b48625
652d82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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 | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚓ Line 11 blocks the refresh script from ever running in this Compose setup. Ye guard uses Proposed patch- if [ -f "$script" ] && [ -x "$script" ] && [[ "$script" == *.sh ]]; then
+ if [ -f "$script" ] && [[ "$script" == *.sh ]]; then
echo "Running $script"
- "$script"
+ bash "$script"
fi📝 Committable suggestion
Suggested change
|
||||||||||||
| echo "Running $script" | ||||||||||||
| "$script" | ||||||||||||
| fi | ||||||||||||
| done | ||||||||||||
| fi | ||||||||||||
|
Comment on lines
+8
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 Line 8-16 runs DB maintenance before Postgres is up, so psql-based init scripts can fail hard. The wrapper executes scripts before Line 19 delegates to the official entrypoint. But Safer direction-# 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 "$@"
+# NOTE: DB-dependent scripts must run only after postgres is accepting connections.
+# Consider moving collation refresh to:
+# 1) a post-start one-shot job (after healthcheck), or
+# 2) logic that explicitly starts/stops a temporary server before running scripts.
+exec /usr/local/bin/docker-entrypoint.sh "$@" |
||||||||||||
|
|
||||||||||||
| # Invoke the original postgres entrypoint | ||||||||||||
| exec /usr/local/bin/docker-entrypoint.sh "$@" | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| rm -f /tmp/needs_refresh.txt | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.