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

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?

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!

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.

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.

My quick way to disable that message: (macOS 12 Monterey M1)
Open Terminal -> Preferences -> Advanced tab -> uncheck to Set locale environment variables on startup

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

Related

microk8s wont start: The exported locale is "C.UTF-8" but it is not supported

We are trying to install microk8s in Centos 7.9 and it wont start. We get an error message as below:
# snap --version
snap 2.57.6-2.el7
snapd 2.57.6-2.el7
series 16
centos 7
kernel 3.10.0-1160.81.1.el7.x86_64
# microk8s version
MicroK8s v1.26.1 revision 4595
[root# ~]# snap logs microk8s
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: File "/snap/microk8s/4595/usr/lib/python3/dist-packages/click/_unicodefun.py", line 118, in _verify_python3_env
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: 'for mitigation steps.' + extra)
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult http://click.pocoo.org/python3/for mitigation steps.
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: This system lists a couple of UTF-8 supporting locales that
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: you can pick from. The following suitable locales where
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: discovered: aa_DJ.utf8, aa_ER.utf8, aa_ET.utf8, af_ZA.utf8, am_ET.utf8, an_ES.utf8, ar_AE.utf8, ar_BH.utf8, ar_DZ.utf8, ar_EG.utf8, ar_IN.utf8, ar_IQ.utf8, ar_JO.utf8, ar_KW.utf8, ar_LB.utf8, ar_LY.utf8, ar_MA.utf8, ar_OM.utf8, ar_QA.utf8, ar_SA.utf8, ar_SD.utf8, ar_SY.utf8, ar_TN.utf8, ar_YE.utf8, as_IN.utf8, ast_ES.utf8, ayc_PE.utf8, az_AZ.utf8, be_BY.utf8, bem_ZM.utf8, ber_DZ.utf8, ber_MA.utf8, bg_BG.utf8, bho_IN.utf8, bn_BD.utf8, bn_IN.utf8, bo_CN.utf8, bo_IN.utf8, br_FR.utf8, brx_IN.utf8, bs_BA.utf8, byn_ER.utf8, ca_AD.utf8, ca_ES.utf8, ca_FR.utf8, ca_IT.utf8, crh_UA.utf8, cs_CZ.utf8, csb_PL.utf8, cv_RU.utf8, cy_GB.utf8, da_DK.utf8, de_AT.utf8, de_BE.utf8, de_CH.utf8, de_DE.utf8, de_LU.utf8, doi_IN.utf8, dv_MV.utf8, dz_BT.utf8, el_CY.utf8, el_GR.utf8, en_AG.utf8, en_AU.utf8, en_BW.utf8, en_CA.utf8, en_DK.utf8, en_GB.utf8, en_HK.utf8, en_IE.utf8, en_IN.utf8, en_NG.utf8, en_NZ.utf8, en_PH.utf8, en_SG.utf8, en_US.utf8, en_ZA.utf8, en_ZM.utf8, en_ZW.utf8, es_AR.utf8, es_BO.utf8, es_CL.utf8, es_CO.utf8, es_CR.utf8, es_CU.utf8, es_DO.utf8, es_EC.utf8, es_ES.utf8, es_GT.utf8, es_HN.utf8, es_MX.utf8, es_NI.utf8, es_PA.utf8, es_PE.utf8, es_PR.utf8, es_PY.utf8, es_SV.utf8, es_US.utf8, es_UY.utf8, xh_ZA.utf8, yi_US.utf8, yo_NG.utf8, yue_HK.utf8, zh_CN.utf8, zh_HK.utf8, zh_SG.utf8, zh_TW.utf8, zu_ZA.utf8
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: Click discovered that you exported a UTF-8 locale
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: but the locale system could not pick up from it because
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: it does not exist. The exported locale is "C.UTF-8" but it
2023-02-13T19:21:58-05:00 microk8s.daemon-apiserver-kicker[16637]: is not supported

Setting up ERP-next in Mac

I have followed the GitHub to setup. I have installed pip, MariaDB, bench, Redis.
After I run the command bench init frappe-bench and cd frappe-bench I don't allow me to create a new site. The following is an error that IO encountered.
/usr/local/Cellar/python/3.7.5/bin/python3.7: Error while finding module specification for 'frappe.utils.bench_helper' (ModuleNotFoundError: No module named 'frappe')
Usage: bench [OPTIONS] COMMAND [ARGS]...
Try "bench --help" for help.
Error: No such command "new-site".
I have also changed in my.conf to
[mysqld]
innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
After bench init frappe-bench
cd env
source env/bin/activate
pip install -e ./apps/frappe --no-cache-dir
bench build
Reference: https://discuss.erpnext.com/t/mac-os-setup-failed/53422/3

setting locale and language in terminal problem

I use zsh for my terminal with iterm2 (macOS 14 Mojave). I get numerous numerous numerous issues with setting the locale and language. the most recent issue being that I can't use cocopods for my ionic application because gems can't be as root. This issue comes down because my terminal needs to have UTF-8 encoding, which it does. I have had this issue so so so much that I have put export LANG=en_US.UTF-8 in the .zshrc file, the .profile file and .bashrc file. I have ran the command $ source ~/.zshrc on ALL of the files mentioned above. I have closed terminal completely, and restarted my computer. No matter what happens and whenever I look inside the file ALL that information is there. the same issue happens whenever I try to open up neo vim I get the output:
Warning: Failed to set locale category LC_NUMERIC to en_ES.UTF-8.
Warning: Failed to set locale category LC_TIME to en_ES.UTF-8.
Warning: Failed to set locale category LC_COLLATE to en_ES.UTF-8.
Warning: Failed to set locale category LC_MONETARY to en_ES.UTF-8.
Warning: Failed to set locale category LC_MESSAGES to en_ES.UTF-8.
here is my .zshrc
export ZSH="/Users/me/.oh-my-zsh"
export LC_ALL=en_ES.UTF-8
export LC_NUMERIC=en_ES.UTF-8.
export LC_TIME=en_ES.UTF-8.
export LC_COLLATE=en_ES.UTF-8.
export LC_MONETARY=en_ES.UTF-8
export LC_MESSAGES=en_ES.UTF-8.
export LANG=en_US.UTF-8
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir rbenv vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time)
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=’red’
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%f"
local user_symbol="$"
if [[ $(print -P "%#") =~ "#" ]]; then
user_symbol = "#"
fi
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%{%B%F{black}%K{yellow}%} $user_symbol%{%b%f%k%F{yellow}%} %{%f%}"
plugins=(
git
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
echo -e "\033]6;1;bg;red;brightness;18\a"
echo -e "\033]6;1;bg;green;brightness;26\a"
echo -e "\033]6;1;bg;blue;brightness;33\a"
then this is what I get from nvim when running the :checkhealth
========================================================================
## Configuration
- OK: no issues found
## Performance
- OK: Build type: Release
## Remote Plugins
- OK: Up to date
## terminal
- INFO: key_backspace (kbs) terminfo entry: key_backspace=^H
- INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
- INFO: $TERM_PROGRAM='vscode'
- INFO: $COLORTERM='truecolor'
health#provider#check
========================================================================
no matter what I do I cannot set the lang or utf or ANYTHING that has to do with that
on my .zshrc file I added the following
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
The answer is based on: https://github.com/vim/vim/issues/4556#issuecomment-503030484
Note that at the time when I found out the answer I wasn't allowed to post an answer because there wasn't enough time that passed.
As for the asnwer why this works. I have no idea, I am not too familiar with this type of Linux/shell permissions, encoding, etc.
Try to export the following in your .zshrc
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
The answer is based on: https://github.com/vim/vim/issues/4556#issuecomment-503030484

Chef PostgreSQL Cookbook Installs Wrong Version on RHEL 7

Running the latest version (6.1.1) of the postgresql Chef cookbook (https://supermarket.chef.io/cookbooks/postgresql) with
node.default['postgresql']['enable_pgdg_yum'] = 'true'
node.default['postgresql']['version'] = '9.3'
This installs postgresql in /var/lib/pgsql/9.3, but running
psql -V
returns
psql (PostgreSQL) 9.2.33
You have to overwrite more at least version, dir, client, contrib and server packages:
node.default["postgresql"]["version"] = "9.3"
node.default["postgresql"]["dir"] = "/etc/postgresql/9.3/main"
node.default["postgresql"]["client"]["packages"] = ["postgresql-client-9.3", "libpq-dev"]
node.default["postgresql"]["server"]["packages"] = ["postgresql-9.3"]
node.default["postgresql"]["contrib"]["packages"] = ["postgresql-contrib-9.3"
It is just an example, I am not sure about package names, double check it. It is due to the way ruby evaluates strings.

locale issue workaround in PostgreSQL data directory upgrade from 8.4 to 9.5

Desciption of the issue is given at link. It seems that it is a PostgreSQL bug only. To resolve this issue, there seems to be only a single workaround, which is to create a list of locale (map) with key as <Language>_<Country>.<CodePage>and value as <Language>, <Country>.
For example:
English_United States.1252 = English, United States
...
Since value of parameter --locale is accepted in the format of <Language>, <Country>whereas output of command SHOW LC_COLLATE is in the format of <Language>_<Country>.<CodePage>. So, during an ugrade I will get the value of lc_collate cmd and get the corresponding value from the list and provide it during PostgreSQL 9.5 installation.
How do I convert <Language>_<Country>.<CodePage> to appropriate format for successful installation ?