Thread: failing to make LATIN1 on locale C system - what am I doing wrong?

failing to make LATIN1 on locale C system - what am I doing wrong?

From
marc rassbach
Date:
Trying to do what maia mailguard says: http://www.maiamailguard.com/maia/wiki/Install
"NOTE: Newer versions of PostgreSQL use UTF8 encoding by default, which is not supported by all of the tools that Maia requires. To avoid encoding errors, PostgreSQL users should use:
pgsql> CREATE DATABASE maia WITH ENCODING 'LATIN1';"


The most popular web-based answer is variations on 'nuke template0 and pick LATIN1'

Yet the postgresql documentation says: https://www.postgresql.org/docs/9.4/static/sql-createdatabase.html
"The character set encoding specified for the new database must be compatible with the chosen locale settings (LC_COLLATE and LC_CTYPE). If the locale is C (or equivalently POSIX), then all encodings are allowed,"

So what am I missing when I do the below and it doesn't work?

$ psql template1
psql (9.4.7)
Type "help" for help.

template1=# CREATE DATABASE music ENCODING 'LATIN1' TEMPLATE template0;
ERROR:  encoding "LATIN1" does not match locale "en_US.UTF-8"
DETAIL:  The chosen LC_CTYPE setting requires encoding "UTF8".
template1-# \q
$ locale
LANG=
LC_CTYPE="C"
LC_COLLATE="C"
LC_TIME="C"
LC_NUMERIC="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=
$ whoami
pgsql

And it "works fine" if I don't try latin1:

$ psql template1
psql (9.4.7)
Type "help" for help.

template1=# CREATE DATABASE music ENCODING 'UTF8' TEMPLATE template0;
CREATE DATABASE
template1=# drop database music;
DROP DATABASE
template1=# \q
$

Re: failing to make LATIN1 on locale C system - what am I doing wrong?

From
Albe Laurenz
Date:
marc rassbach wrote:
> Trying to do what maia mailguard says: http://www.maiamailguard.com/maia/wiki/Install
> "NOTE: Newer versions of PostgreSQL use UTF8 encoding by default, which is not supported by all of the
> tools that Maia requires. To avoid encoding errors, PostgreSQL users should use:
> pgsql> CREATE DATABASE maia WITH ENCODING 'LATIN1';"
> 
> 
> The most popular web-based answer is variations on 'nuke template0 and pick LATIN1'

I don't understand what you mean by that ...

> Yet the postgresql documentation says: https://www.postgresql.org/docs/9.4/static/sql-
> createdatabase.html
> "The character set encoding specified for the new database must be compatible with the chosen locale
> settings (LC_COLLATE and LC_CTYPE). If the locale is C (or equivalently POSIX), then all encodings are
> allowed,"
> 
> So what am I missing when I do the below and it doesn't work?
> 
> $ psql template1
> psql (9.4.7)
> Type "help" for help.
> 
> template1=# CREATE DATABASE music ENCODING 'LATIN1' TEMPLATE template0;
> ERROR:  encoding "LATIN1" does not match locale "en_US.UTF-8"
> DETAIL:  The chosen LC_CTYPE setting requires encoding "UTF8".
> template1-# \q

[...]

> And it "works fine" if I don't try latin1:
> 
> $ psql template1
> psql (9.4.7)
> Type "help" for help.
> 
> template1=# CREATE DATABASE music ENCODING 'UTF8' TEMPLATE template0;
> CREATE DATABASE

You should use:

CREATE DATABASE music TEMPLATE template0 LC_COLLATE="C" LC_CTYPE="C";

Yours,
Laurenz Albe

Re: failing to make LATIN1 on locale C system - what am I doing wrong?

From
marc rassbach
Date:


On Mon, Jun 27, 2016 at 2:46 AM, Albe Laurenz <laurenz.albe@wien.gv.at> wrote:

You should use:

CREATE DATABASE music TEMPLATE template0 LC_COLLATE="C" LC_CTYPE="C";

Yours,
Laurenz Albe

Thank you for the rabbit-trail that lead here: 
 
template1=# CREATE DATABASE music ENCODING 'LATIN1' TEMPLATE template0 LC_COLLATE='C' LC_CTYPE='C';
CREATE DATABASE
template1=# \l
                            List of databases
   Name    | Owner | Encoding | Collate |    Ctype    | Access privileges
-----------+-------+----------+---------+-------------+-------------------
 music     | pgsql | LATIN1   | C       | C           |
 postgres  | pgsql | UTF8     | C       | en_US.UTF-8 |
 template0 | pgsql | UTF8     | C       | en_US.UTF-8 | =c/pgsql         +
           |       |          |         |             | pgsql=CTc/pgsql
 template1 | pgsql | UTF8     | C       | en_US.UTF-8 | =c/pgsql         +
           |       |          |         |             | pgsql=CTc/pgsql