Change locale of Postgresql database

I had an issue with search implementation in my app: search for records in Russian worked, but was case sensitive. I found out, that I have to change locale of my database (specifically it’s categories LC_COLLATE and LC_CTYPE) to ru_RU.UTF-8. But you can’t change it for existing database - locale should be defined when database gets created. So the steps should be:

  1. drop existing database
  2. check list of locales of your system: type locale -a in your terminal, find the name of locale that you want to change to
  3. add to you database.yml following configuration:
default: &default
  adapter: postgresql
  encoding: utf8
  ctype: ru_RU.UTF-8 
  collation: ru_RU.UTF-8
  template: template0

value of ctype and collation should be the same as the locale name in your system.

After that problem was solved locally, but code didn’t pass Semaphore pipeline. After mailing with their support and adjusting proposed solution, I did following:

  1. added Dockerfile to the repo with following congifuration:
FROM postgres:9.6
RUN localedef -i ru_RU -c -f UTF-8 -A /usr/share/locale/locale.alias ru_RU.UTF-8
  1. added a job in semaphore.yml to re-create postgres docker image with new locale:
- docker build --tag postgres:lang .
- docker run --rm --net host -d -e POSTGRES_PASSWORD=semaphore --name postgres -v /var/run/postgresql:/var/run/postgresql postgres:lang

Now it works properly. For more information about locale support check