Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make resilient to missing /etc/default/locale file - causes Postgres to install as ASCII rather than UTF8 #25

Open
mvl22 opened this issue Nov 29, 2014 · 2 comments

Comments

@mvl22
Copy link
Member

mvl22 commented Nov 29, 2014

On the new live server, but not on a test VM oddly, I'm getting this failure:

script[Create the database] action runPG::InvalidParameterValue: ERROR:  new encoding (UTF8)
is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "cyclescape_production" ENCODING = 'unicode'

Postgres has the following databases on the live server:

postgres=# \l

postgres    SQL_ASCII
template0    SQL_ASCII
template1    SQL_ASCII

with the shell command 'locale' giving:

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

Hmm... on the VM, I get:

postgres=# \l

postgres    UTF8
template0    UTF8
template1    UTF8

with the shell command 'locale' giving:

$ locale
LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

I wonder if there is some kind of system setting that is wrong on the new server. (If so, we probably need to detect this.)

Potentially useful links:

@mvl22
Copy link
Member Author

mvl22 commented Jan 15, 2015

I found the problem, and the Chef repo needs to be made resilient to this.

Basically the server seems not to have an /etc/default/locale file which should contain

LANG="en_GB.UTF-8"
LANGUAGE="en_GB:en"

Accordingly, our Postgres install ends up with ASCII databases, not UTF8, causing our application not to install later on.

I've found the same problem described here:
https://bugs.launchpad.net/maas/+bug/1382774

DOES work, resulting in UTF8:

su root
echo "LC_ALL=en_GB.UTF-8" >> /etc/default/locale

# Uninstall any previous installation
service postgresql stop
apt-get -y remove --purge postgresql-9.3 postgresql-9.3-postgis-2.1
rm -rf /var/lib/postgresql/
# Reinstall
apt-get -y install postgresql-9.3 postgresql-9.3-postgis-2.1

# The output of this command will CORRECTLY now include the lines:
# "locale en_GB.UTF-8"

DOESN'T work, resulting in ASCII:

su root
rm -f /etc/default/locale

# Uninstall any previous installation
service postgresql stop
apt-get -y remove --purge postgresql-9.3 postgresql-9.3-postgis-2.1
rm -rf /var/lib/postgresql/
# Reinstall
apt-get -y install postgresql-9.3 postgresql-9.3-postgis-2.1

# The output of this command will show the following:
# "missing default/locale"
# "deleted default/locale"
# "locale C"

This is 100% repeatable - replay the blocks and you'll find it either installs as ASCII or installs as UTF8.

@mvl22 mvl22 changed the title 'Create the database' section failing due to encoding problem Make resilient to missing /etc/default/locale file - causes Postgres to install as ASCII rather than UTF8 Jan 15, 2015
@nakic
Copy link

nakic commented Jan 25, 2016

Confirmed problem, used this (as root) to get around the problem:

 for y in $(locale | cut -d '=' -f 2| sort |uniq );do locale-gen $y; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants