What is going wrong with postgresql initdb? Why is the `UTF-8` encoding not getting enforced?

Looks like you are calling initdb through a runlevel script of the OS. This script might not pass on the parameters. You better try executing initdb directly, you will need to perform the following steps starting as root and assuming the OS user account for the database is postgres.

mkdir <your data dir>
chown postgres <your data dir>
su postgres
initdb --pgdata=<your data dir> -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8'

Debian PostgreSQL installation automatically calls the initdb i.e. it initializes the cluster with default encoding and locale. Encoding can be changed later but the locale cannot. To change the locale (an possibly other options in initdb), delete the existing default cluster and create a new one:

Take root privileges.
Run the following command:



 pg_dropcluster --stop <version> main

For example:

pg_dropcluster --stop 8.3 main

Run the initdb with your options. For example:

pg_createcluster --locale de_DE.UTF-8 --start 8.3 main

Warning!

The previous operation obviously deletes everything you had in cluster databases. Perform this operation right after you have installed the base package. Check the PostgreSQL manual if you need to change locale for an existing database (it is not a trivial operation).