akumria / puppet-postgresql

Manage and install Postgresql databases and users
37 stars 20 forks source link

How to get template0 and template1 created with UTF-8 encoding #7

Closed codeinthehole closed 11 years ago

codeinthehole commented 11 years ago

Am having a few problems getting the default encoding set correctly. After installation, the template databases are created with encoding::

$ sudo -u postgres psql --list
                                     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

As far as I can tell, the default encoding is taken from your locale. However, this doesn't seem to be working in my case as my locale settings are all UTF-8::

$ locale
LANG=en_GB.utf8
LANGUAGE=
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=

Strangely when I run apt-get install postgresq-9.1 manually, the database are created correctly. Any idea what the problem is?

codeinthehole commented 11 years ago

Don't worry about this one - it turns out I needed a reboot to get Vagrant to pick up my new locale settings.

akumria commented 11 years ago

Hi David,

What has likely happened is that the locale was installed but then not generated, this happens on reboot with Debian / Ubuntu.

I use saz/locales to cover this case myself (although I also reboot during the initial installation for other reasons)

adamyonk commented 11 years ago

Tried fixing this with saz/puppet-locales to no avail. Does anyone have an example of what they used to get this working?

akumria commented 11 years ago

Hi @adamyonk ,

Sorry I missed this; I've been travelling. This is (a distillation) of what I use:

class {'locales':
    autoupgrade => true,
    locales     => 'en_US.UTF-8 UTF-8',
}

apt::source { 'pitti-postgresql-ppa':
    location    => 'http://ppa.launchpad.net/pitti/postgresql/ubuntu',
    repos       => 'main',
    key         => '8683D8A2',
}

class {'postgresql::server':
    port    => 5432,
    locale  => 'en_GB.UTF-8',
    require => [Locales, Apt::Source['pitti-postgresql-ppa'], ],
}

NOTE: The require line is not what I actually use, so it may require some tweaking as I've not tested this personally.

Hope this helps.