Today I learned how to properly fix this PostgreSQL warning in production:
WARNING: database "myapp_production" has a collation version mismatch
DETAIL: The database was created using collation version 2.36,
but the operating system provides version 2.41.
This typically appears after an OS or glibc upgrade. Your Rails app will continue to work, but PostgreSQL warns that text sorting and indexes may be inconsistent.
Why this matters
Collation affects:
ORDER BYLIKE / ILIKE- indexes on
textandvarchar
Ignoring the warning can lead to subtle bugs, not crashes.
The fix (safe & recommended)
Since the app is deployed with Kamal, I ran the maintenance commands from inside the app container.
1. Exec into the running container and open the database console
kamal app exec -i "bin/rails dbconsole"
Rails handles the correct connection details and avoids Unix socket issues.
2. Refresh the collation version
ALTER DATABASE myapp_production REFRESH COLLATION VERSION;
This updates PostgreSQL's metadata to acknowledge the new OS collation rules.
3. Rebuild indexes
REINDEX DATABASE myapp_production;
⚠️ This briefly locks tables, so run it during low-traffic hours.
4. Verify
bin/rails console
The warning should no longer appear.
Takeaways
- This is a PostgreSQL maintenance task, not a Rails bug
- OS upgrades can require manual DB follow-up
- Kamal is perfectly fine for running one-off production maintenance
- Always rebuild indexes after refreshing collation
Short, practical, and now future-me won’t panic the next time I see that warning 😄
Top comments (0)