7

After an upgrade from Ubuntu Server 14.04 to 16.04 I had to also upgrade my Postgres clusters from 9.3 to 9.5. The normal way to do that is to first drop the (empty) 9.5 cluster that the upgrade created:

# pg_dropcluster 9.5 main

and then to upgrade the old 9.3 cluster to 9.5:

# pg_upgradecluster 9.3 main

This however results in an error:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = (unset),
LC_PAPER = "nl_NL.UTF-8",
LC_ADDRESS = "nl_NL.UTF-8",
LC_MONETARY = "nl_NL.UTF-8",
LC_NUMERIC = "nl_NL.UTF-8",
LC_TELEPHONE = "nl_NL.UTF-8",
LC_IDENTIFICATION = "nl_NL.UTF-8",
LC_MEASUREMENT = "nl_NL.UTF-8",
LC_TIME = "nl_NL.UTF-8",
LC_NAME = "nl_NL.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
Error: The locale requested by the environment is invalid.
Error: Could not create target cluster

This means I could not upgrade to Postgres 9.5.

I checked all locale settings:

  • the en_US.UTF-8 locale exists and is properly generated as checked with locale -a (it shows en_US.utf8 in its list)
  • The file /etc/environment contains LC_ALL=en_US.UTF-8 and LANG=en_US.UTF-8
  • /etc/default/locale contains the same setting for LANG, LANGUAGE and LC_ALL
  • I can start Perl without any issue using "perl -e exit"

The error message is generated from the pg_createcluster script which is called from pg_updatecluster. But running pg_createcluster from the command line works just fine, without any issue.

Workaround for the issue:

I used the following workaround to at least get the conversion to work. I edited the /usr/bin/pg_upgradecluster script, as follows:

  • Find the code where it calls pg_createcluster by looking for the comment "create new cluster"
  • That code consists of a series of "push" statements, ending in the suspicious line: delete $ENV{'LC_ALL'}
  • Notice that this LC_ALL is exactly the variable that is unset in the error message.
  • Comment out that delete comment by adding a '#' before it, then save.

This at least circumvents this problem and lets you run the upgrade.

My question: is this a bug in the pg_upgradecluster script, or is something else awry on my system?

fjalvingh
  • 790
  • 1
  • 8
  • 20
  • 1
    Related article: https://stackoverflow.com/questions/49089099/perl-fails-to-set-locale-even-though-it-is-installed – Khoi Ngo Apr 06 '22 at 10:01

5 Answers5

5

had the same problem on an ubuntu 16.04 server. what helped in my case was to generate all the locales that appear in your listing of $ locale:

$ sudo locale-gen "en_US.UTF-8"
$ sudo locale-gen "nl_NL.UTF-8"

good luck!

hiro protagonist
  • 44,693
  • 14
  • 86
  • 111
4

In my case, it was complaining about

Error: The locale requested by the environment is invalid:
LANG: en_GB
LANGUAGE: en_GB:en

So I unset LANG and unset LANGUAGE and it worked.

insideClaw
  • 323
  • 1
  • 8
1

For me, I have followed many suggestions and still didn't work. The script mentioned

LC_TIME=en_UK but it's totally unrelated so I ignored it at first. Turns out this was the problem and doing "unset LC_TIME" was all I needed.

Posting here in case it happened to someone else.

Ramast
  • 7,157
  • 3
  • 32
  • 32
0

My quick way to disable that message: (macOS 12 Monterey M1)

Open Terminal -> Preferences -> Advanced tab -> uncheck to Set locale environment variables on startup

Khoi Ngo
  • 941
  • 8
  • 16
0

Just came across this in fresh Ubuntu + PostgresQL install, after all those years.. either way, the solution is:

apt-get install locales
user3136781
  • 71
  • 1
  • 5