Solved: Encoding problems


#1

Hallo,

I wanted to install a mastodon instance on an Ubuntu 16.04 server hosted by contabo.de. I’ve followed the official tutorial, but when I want to create the database I get the following error message:

mastodon@server:~/live$RAILS_ENV=production bundle exec rails db:setup
PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".
: CREATE DATABASE "mastodon_production" ENCODING = 'unicode'
Couldn't create database for {"adapter"=>"postgresql", "pool"=>5, "timeout"=>5000, "encoding"=>"unicode", "database"=>"mastodon_production", "username"=>"mastodon", "password"=>nil, "host"=>"/var/run/postgresql", "port"=>5432, "prepared_statements"=>true}
rails aborted!
ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".
: CREATE DATABASE "mastodon_production" ENCODING = 'unicode'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `async_exec'
....

Can someone help me?


#2

Solved it: Gone back to a snapshot of my server before I started the installation.
Generated the en_US.UTF-8 locales:

sudo locale-gen en_US.UTF-8

edited the /etc/default/locale en_US -> en_US.UTF-8

and restarted the server. I’ve been able to setup the database afterwords.


#3

Try to change your server’s locale to en_US.UTF-8. If you don’t know how or can’t do it, a temporary command can help:

env LANG=en_US.UTF-8 RAILS_ENV=production bundle exec rails db:setup

and later prefixing all commands with env LANG=en_US.UTF-8

If it still complains, please provide the output of echo $LANG && env | grep ^LC_