Skip to content

Instantly share code, notes, and snippets.

@Edu4rdSHL
Created February 5, 2024 06:21
Show Gist options
  • Save Edu4rdSHL/80b63375730c6f2104dac62ea12cb97f to your computer and use it in GitHub Desktop.
Save Edu4rdSHL/80b63375730c6f2104dac62ea12cb97f to your computer and use it in GitHub Desktop.
Fix postgres collation version mismatch
#!/bin/bash
# PostgreSQL connection parameters
PG_USER="postgres"
PG_HOST="localhost"
PG_PORT="5432"
# Get a list of databases
databases=$(psql -U $PG_USER -h $PG_HOST -p $PG_PORT -q -t -c "SELECT datname FROM pg_database")
# Iterate through each database and execute the command
for database in $databases; do
echo "Refreshing collation version for database: $database"
psql -U $PG_USER -h $PG_HOST -p $PG_PORT -d $database -c "REINDEX DATABASE $database"
psql -U $PG_USER -h $PG_HOST -p $PG_PORT -d $database -c "ALTER DATABASE $database REFRESH COLLATION VERSION"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment