Skip to content

Instantly share code, notes, and snippets.

@gacha
Last active March 4, 2020 12:59
Show Gist options
  • Save gacha/b9121b85e487c47d7f67 to your computer and use it in GitHub Desktop.
Save gacha/b9121b85e487c47d7f67 to your computer and use it in GitHub Desktop.

PostgreSQL setup

To use lv_LV.UTF-8 locale your unix system should have it, check it:

$ locale -a

If it's not here, then on linux as root uncomment it in /etc/locale.gen and run locale-gen. Then restart PostgreSQL server.

Open postgres shell:

$ su postgres
$ psql

Check available collations:

postgres=# select * from pg_collation;

If LV not found then create it:

postgres=# create collation lv_LV (locale = 'lv_LV.utf8');

On rails 4 you can add these to database.yml and just create the DB:

encoding: utf8
ctype: lv_LV.utf8
collation: lv_LV.utf8
template: template0

but on rails 3 you have 2 options:

  1. Re-init your database initdb --locale=lv_LV.UTF-8 --lc-ctype=lv_LV.UTF-8 --lc-collate=lv_LV.UTF-8 and now all databases by default will use lv_LV.UTF-8

  2. Drop current database and create it with template0 and specify collation:

    create database myapp_development template template0 encoding 'utf8' lc_collate 'lv_LV.utf8' lc_ctype 'lv_LV.utf8'; create database myapp_test template template0 encoding 'utf8' lc_collate 'lv_LV.utf8' lc_ctype 'lv_LV.utf8';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment