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?