Fix for: character of encoding “UTF8” has no equivalent in “LATIN1”, Ubuntu & Vagrant

This is mostly a post for if I happen over this problem again in the future.

Related to: “DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.”

The solution I found is a bit of a hack. Really you want to find why postgres has created its databases in LATIN1 encoding before installing postgres.

This script however will recreate them correctly so you can get on with some work. Run it before creating your application database(s).

#!/usr/bin/env bash
# This script changes postgres from LATIN1 to UTF8
pg_dumpall > /tmp/postgres.sql
pg_dropcluster --stop 9.1 main
pg_createcluster --locale en_US.UTF-8 --start 9.1 main
psql -f /tmp/postgres.sql

One thought on “Fix for: character of encoding “UTF8” has no equivalent in “LATIN1”, Ubuntu & Vagrant

  1. Karthik Viswanathan

    Thanks so much! I couldn’t restore my postgres dump for the longest time until finding this post. Really appreciate it.

    Reply

Leave a Reply to Karthik Viswanathan Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*