DEV Community

Cover image for TIL: How to Fix a PostgreSQL Collation Version Warning in a Kamal-Deployed Rails App
Jess Alejo
Jess Alejo

Posted on

TIL: How to Fix a PostgreSQL Collation Version Warning in a Kamal-Deployed Rails App

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.
Enter fullscreen mode Exit fullscreen mode

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 BY
  • LIKE / ILIKE
  • indexes on text and varchar

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"
Enter fullscreen mode Exit fullscreen mode

Rails handles the correct connection details and avoids Unix socket issues.


2. Refresh the collation version

ALTER DATABASE myapp_production REFRESH COLLATION VERSION;
Enter fullscreen mode Exit fullscreen mode

This updates PostgreSQL's metadata to acknowledge the new OS collation rules.


3. Rebuild indexes

REINDEX DATABASE myapp_production;
Enter fullscreen mode Exit fullscreen mode

⚠️ This briefly locks tables, so run it during low-traffic hours.


4. Verify

bin/rails console
Enter fullscreen mode Exit fullscreen mode

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)