Skip to content

Instantly share code, notes, and snippets.

@plusplus
Last active December 21, 2015 06:39
Show Gist options
  • Save plusplus/6265438 to your computer and use it in GitHub Desktop.
Save plusplus/6265438 to your computer and use it in GitHub Desktop.
vagrant@precise64:/vagrant/prereqs-rhel-v3$ sudo -u postgres createdb -O postgres -E utf8 -T template0 dbname
createdb: database creation failed: ERROR: encoding UTF8 does not match locale en_US
DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.
vagrant@precise64:/vagrant/prereqs-rhel-v3$
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
echo "UPDATE default encoding for new databases"
(cat <<'EOF'
update pg_database set datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with ENCODING = 'UTF-8' LC_CTYPE = 'en_US.utf8' LC_COLLATE = 'en_US.utf8' template = template0;
update pg_database set datistemplate = TRUE where datname = 'template1';
EOF
) > /tmp/fix_encoding.sql
sudo -u postgres psql -f /tmp/fix_encoding.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment