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'
....
sudo su postgres
psql
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';
\q