I am trying to configure postgresql in a Vagrant field using a Chef solo and I am encountering some problems. I need the default postgres encoding / locale to be UTF8. By default, the locale of the exact 64-bit Ubuntu is set to "C", so postgres uses LATIN1 for encoding. This is what I have done so far:
I have a chef recipe that sets the locale by doing the following:
template "/etc/profile.d/lang.sh" do
source "lang.sh.erb"
mode "0644"
end
execute "locale-gen" do
command "locale-gen en_US.UTF-8"
end
execute "dpkg-reconfigure-locales" do
command "dpkg-reconfigure locales"
end
where lang.sh.erb looks like this:
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
It sets the locale correctly, but unfortunately it does not change the current environment. So I have another recipe that just sets ENV before including postgresql
ENV["LANGUAGE"] = ENV["LANG"] = ENV["LC_ALL"] = "en_US.UTF-8"
include_recipe "postgresql::server"
It does not affect. The locale is configured correctly:
postgres@precise64:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
But postgres used the locale standard "C" when it was installed.
postgres@precise64:~$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
http://www.softr.li/blog/2012/05/22/chef-recipe-to-install-a-postgresql-server-on-a-machine-configured-with-en_us-locales.