Inactive settings for the chef

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.

+4
3

, , , bootstrap script, , /etc/default/lang.sh . ( ) lang :

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

​​ UTF-8. , , , , , ...

+3

-.

postgresql cookbook node['postgresql']['initdb_locale'] . , name: server .kitchen.yml:

attributes:
  postgresql:
    initdb_locale: "en_US.UTF_8"
+1

After the fact, you can delete and recreate the postgres template database as UTF-8. Not an ideal solution, but it really works in your chef's recipe. See: http://www.pebra.net/blog/2013/06/10/when-struggling-with-postgresql-and-utf8-slash-latin/

include_recipe "postgresql::server"
include_recipe "database::postgresql"

execute "Psql template1 to UTF8" do
user "postgres"
command <<-SQL
echo "
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE' LC_CTYPE='en_US.utf8'      LC_COLLATE='en_US.utf8';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\\c template1
VACUUM FREEZE;" | psql postgres -t
SQL
# only_if '[ $(echo "select count(*) from pg_database where datname = \'template1\' and datcollate = \'en_US.utf8\'" |psql postgres -t) -eq 0 ]'
end
+1
source

All Articles