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:
- In your vagrant,
psql
. You should see a postgres prompt. - 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';
- 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.