Skip to content

Instantly share code, notes, and snippets.

@interlock
Created November 9, 2016 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interlock/cabe50ec573b6ec880e0b67f8ae038d4 to your computer and use it in GitHub Desktop.
Save interlock/cabe50ec573b6ec880e0b67f8ae038d4 to your computer and use it in GitHub Desktop.

Is you attempt to do a bin/rails db:setup or something similar and it complains like this:

PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".

Run these commands:

  1. In your vagrant, psql. You should see a postgres prompt.
  2. Run each of these lines of SQL one at a time:
  • update pg_database set datistemplate=false where datname='template1';
  • drop database Template1;
  • create database template1 with owner=postgres encoding='UTF-8' lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
  • update pg_database set datistemplate=true where datname='template1';
  1. Rejoice, your locale is now fixed in postgresql. A vagrant image update is coming later this week or next :-|

What the above does:

  • normally new databases copy of default settings from the template1 database. Because of it's importance, it is protected from being deleted. The first command removes that restriction.
  • We drop the database, gone for ever. No turning back now.
  • We create a new template1 database from... template0 database. We set the locale to support north american english with fancy pants UTF-8 (aka, Shit Emoji support)
  • We return template1 to its warm blanket of protection, marking it as a template once more.

The problem, for those curious, was the default install of Ubuntu does not set support for utf-8 by default (a terrible default IMHO). This changes how many programs run, including progresql. Which, by default, will initialize with the systems locale.

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