L
L
lovesuper2014-04-15 19:00:35
PostgreSQL
lovesuper, 2014-04-15 19:00:35

How to set utf8 locale for postgresql?

When init, the database gives the application an error: UnicodeEncodeError
: 'latin-1' codec can't encode characters in position 0-6: ordinal not in range(256 ) 'UTF8'; ERROR: encoding UTF8 does not match locale en_US DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1. I set the ru_RU locale to the originally English ubuntu, but all attempts to reassign the locale for postgres were unsuccessful.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
whats, 2014-04-21
@lovesuper

I struggled with this myself for a long time.
Turn on the console
Delete the old database cluster
pg_dropcluster --stop 9.1(cluster version) main(cluster name, you can get pg_lsclusters)
Create a new cluster
pg_createcluster --locale de_DE.UTF-8 --start 9.3 main
In this case, the locale must be set
dpkg- reconfigure locales

A
Alexey Lesovsky, 2014-04-16
@lesovsky

to this we also need to add TEMPLATE = template0.
those. succeed

CREATE DATABASE "имя_базы"
  WITH OWNER "postgres"
  ENCODING 'UTF8'
  LC_COLLATE = 'ru_RU.UTF-8'
  LC_CTYPE = 'ru_RU.UTF-8'
  TEMPLATE = template0;

K
Konstantin Kozhin, 2014-04-15
@kkzhn

Try like this:

CREATE DATABASE "имя_базы"
  WITH OWNER "postgres"
  ENCODING 'UTF8'
  LC_COLLATE = 'ru_RU.UTF-8'
  LC_CTYPE = 'ru_RU.UTF-8';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question