jeremy_rutman
jeremy_rutman

Reputation: 5720

postgres createdb locale woes

I am having a spot of trouble setting up a db due to the following :

$ createdb -E UTF-8 -p 5432 nominatim
createdb: database creation failed: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".
ERROR: Error executing external command: createdb -E UTF-8 -p 5432 nominatim

In /etc/profile I set locale to en_US.UTF-8 and when I check 'locale' as postgres user (or my own user) all vars including LC_CTYPE are 'en_US.UTF-8'. Also, I have run sudo locale-gen en_US en_US.UTF-8 and sudo dpkg-reconfigure locales. Does anyone have a clue why LC_CTYPE seems to be falling back to en_US and not en_US.UTF-8?

Upvotes: 1

Views: 1027

Answers (1)

Nick Barnes
Nick Barnes

Reputation: 21336

The default locale for a cluster is set by initdb:

Locale support is automatically initialized when a database cluster is created using initdb. initdb will initialize the database cluster with the locale setting of its execution environment by default [...] If you want to use a different locale (or you are not sure which locale your system is set to), you can instruct initdb exactly which locale to use by specifying the --locale option.

You can override the default for a new database with createdb --locale.

If you really need to modify the default for an existing cluster, you can drop and recreate template1 with a different locale (see this example).

Upvotes: 1

Related Questions