Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change LC_CTYPE for PostgreSQL and PostGIS use

So I'm walking through the GeoDjango tutorial and I'm stuck on this error message:

postgres@lucid32:~$ createdb -E UTF8 template_postgis
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.

I've googled and read some Ubuntu docs but to no avail. Any insight would be greatly appreciated!

I'm using the default Vagrant Box lucid 32, for testing out my setup.

like image 419
a.m. Avatar asked Dec 02 '11 03:12

a.m.


People also ask

What is Lc_ctype in postgres?

The LC_COLLATE and LC_CTYPE settings are determined when a database is created, and cannot be changed except by creating a new database. Other locale settings including LC_MESSAGES and LC_MONETARY are initially determined by the environment the server is started in, but can be changed on-the-fly.

How do I change collate and Ctype in PostgreSQL?

You cannot to change these values for already created databases. In this moment, when there are not other databases, the most easy solution is a) stop database, b) delete data directory, c) run manually initdb with options --encoding and --locale (run this command under postgres user).

What is the default collation in PostgreSQL?

Often the default collation is set by initdb when the PostgreSQL cluster is first created. The collation and other locale components can be set using defaults from the operating system environment, and then inherited by databases created later.


2 Answers

It is better to just specify the locale for the database and have the encoding be figured out from that. So use something like

createdb --locale=en_US.utf8 template_postgis
like image 82
Peter Eisentraut Avatar answered Oct 12 '22 23:10

Peter Eisentraut


Both -E UTF8 and --locale=en_US.utf8 are needed

$ createdb -E UTF8 -T template0 --locale=en_US.utf8 template_postgis
like image 38
aarti Avatar answered Oct 12 '22 23:10

aarti