3
votes

I'm trying to build Vagrant box provisioned with Puppet.

I use Ubuntu 12.04 LTS box from http://files.vagrantup.com/precise64.box.

I also use http://forge.puppetlabs.com/puppetlabs/postgresql module to install PostgreSQL with the following manifest:

class db {
  class { 'postgresql': version => '9.1' }
  class { 'postgresql::server': }
}
class { 'db': }

It installs correctly, but databases are created with SQL_ASCII encoding:

$ psql -l -U postgres
                             List of databases
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges
-----------+----------+-----------+---------+-------+-----------------------
 postgres  | postgres | SQL_ASCII | C       | C     |
 template0 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
 template1 | postgres | SQL_ASCII | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres

After googling I've thought it might be a locale problem, but it looks correct to me:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=
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=

Do you know what should I do to be able to install PostgreSQL with UTF8 encoding default? It'd be also nice to be able to use Puppet for this.

1
Have you seen this issue report? It seems to be related. - Mike Sherrill 'Cat Recall'
That's different puppet module. I use puppetlabs/postgresql. However, I'll try to use workaround mentioned there. - p0deje
It may help (as I see LC_ALL is unset): ubuntuforums.org/showthread.php?t=1720356 - Sasha Koss
Tried setting LC_ALL in /etc/environment before PostgreSQL installation, but it didn't help. - p0deje

1 Answers

12
votes

Apparently, it is Puppet bug http://projects.puppetlabs.com/issues/4695. Added the following code from issue comments as a workaround:

# workaround for http://projects.puppetlabs.com/issues/4695
# when PostgreSQL is installed with SQL_ASCII encoding instead of UTF8
exec { 'utf8 postgres':
  command => 'pg_dropcluster --stop 9.1 main ; pg_createcluster --start --locale en_US.UTF-8 9.1 main',
  unless  => 'sudo -u postgres psql -t -c "\l" | grep template1 | grep -q UTF',
  require => Class['postgresql::server'],
  path    => ['/bin', '/sbin', '/usr/bin', '/usr/sbin'],
}