The relevant option is --locale=locale
to the initdb command which initializes your database cluster. If you don't supply it explicitly it defaults to the system locale. (You probably run your Ubuntu on locale 'C'.)
Read more about it in the excellent manual here.
In PostgreSQL you can still sneak in a database with different locale by basing a new database off template0
instead of the default templeate1
. I quote the manual here:
The encoding and locale settings must match those of the template
database, except when template0 is used as template.
But I'd rather recreate the database cluster with the desired locale. Much cleaner.
Edit: info about available locales
You can only use locales that are provided by the operating system. I quote the manual here:
What locales are available on your system under what names depends on
what was provided by the operating system vendor and what was
installed. On most Unix systems, the command locale -a will provide a
list of available locales. Windows uses more verbose locale names,
such as German_Germany or Swedish_Sweden.1252, but the principles are
the same.
Look at locale-gen
in a Unix-system, if you want to use a locale that has not yet been generated. The important thing to understand is that multiple locales can be installed in your OS, but only one of them can be picked for system parameters like LC_CTYPE
, LC_COLLATE
, etc. Look at the output of locale
versus locale -a
in the shell. Usually it is the same for all, set via LC_ALL
.
@David: What you did may have solved your problem, but you could have had that easier. Also, be aware that the environment variable LANG
only provides the default for all locale settings. If any of them is set to something different, LANG
will be overridden. Set LC_ALL
to override any existing setting. Here is one of many sites in the web telling you more about that.
To check all current locale settings of your database (cluster), run in your database:
SHOW ALL;
Or more specifically:
SELECT *
FROM pg_settings
WHERE name ~~ 'lc%';