How to fix "Error: the locale requested by the environment is invalid" during postgresql cluster upgrade (pg_upgradecluster)

How to fix "Error: the locale requested by the environment is invalid" during postgresql cluster upgrade (pg_upgradecluster)

从 Ubuntu 服务器 14.04 升级到 16.04 后,我还必须将我的 Postgres 集群从 9.3 升级到 9.5。这样做的正常方法是首先删除升级创建的(空)9.5 集群:

# pg_dropcluster 9.5 主

然后将旧的 9.3 集群升级到 9.5:

# pg_upgradecluster 9.3 主

然而这会导致错误:

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

这意味着我无法升级到 Postgres 9.5。

我检查了所有区域设置:

错误消息是由从 pg_updatecluster 调用的 pg_createcluster 脚本生成的。但是从命令行 运行ning pg_createcluster 工作得很好,没有任何问题。

问题的解决方法:

我使用以下解决方法至少使转换工作正常。我编辑了/usr/bin/pg_upgradecluster脚本,如下:

这至少绕过了这个问题,让你运行升级。

我的问题:这是 pg_upgradecluster 脚本中的错误,还是我的系统出现其他问题?

在 ubuntu 16.04 服务器上遇到了同样的问题。对我的情况有帮助的是生成 all 出现在 $ locale:

列表中的语言环境
$ sudo locale-gen "en_US.UTF-8"
$ sudo locale-gen "nl_NL.UTF-8"

祝你好运!

对我来说,我已经听从了很多建议,但仍然没有奏效。 提到的剧本

LC_TIME=en_UK 但它完全不相关,所以一开始我忽略了它。 原来这就是问题所在,我只需要做 "unset LC_TIME"。

张贴在这里以防其他人遇到这种情况。

就我而言,它在抱怨

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

所以我 unset LANGunset LANGUAGE 成功了。

我禁用该消息的快速方法:(macOS 12 Monterey M1)

打开终端 -> 首选项 -> 高级选项卡 -> 取消选中启动时设置语言环境变量