0

I am trying to upgrade a Postgresql 13 database to version 15 using the command pg_upgradecluster 13 main but it keeps failing with this message:

Stopping old cluster...
Restarting old cluster with restricted connections...
Notice: extra pg_ctl/postgres options given, bypassing systemctl for start operation
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "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:
  LANG: en_US.UTF-8
  LC_CTYPE: UTF-8
Error: Could not create target cluster

When I run the locale command, I get the following:

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

I get the same values I do this:

sudo -u postgres -i
locale

The contents of /etc/default/locale:

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8

So where is LC_CTYPE: UTF-8 coming from?

I have executed dpkg-reconfigure locales as well, and only en_US.UTF-8 UTF-8 is selected, and it's set as the default.

UPDATE: the following command worked:

env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 pg_upgradecluster 13 main

But I am still very surprised why this is even necessary on a pretty standard Debian install?

4
  • You can try overriding it: env LC_CTYPE="en_US.UTF-8" pg_upgradecluster 13 main. But perhaps it's complaining that en_US.UTF-8 itself isn't installed. You can check with sudo dpkg-reconfigure locales Commented Apr 7 at 9:50
  • I had executed dpkg-reconfigure locales as well, and only en_US.UTF-8 UTF-8 is selected, and it's set as the default. It's just so weird that this override is even necessary, I have no idea where the error is coming from. Commented Apr 7 at 10:05
  • Checked your shell config files? Commented Apr 7 at 10:09
  • Nothing about locale in there. Also that should be visible when running locale, right? Commented Apr 7 at 10:41

1 Answer 1

0

Question: where is LC_CTYPE: UTF-8 coming from?

The LC_CTYPE: UTF-8 can come from the current Postgresql 13 configurations/cluster.

For example,

admin@i-04aa762bacf0b8a27:/etc/postgresql/13/main$ sudo grep -r locale .
./postgresql.conf:lc_messages = 'C.UTF-8'                       # locale for system error message
./postgresql.conf:lc_monetary = 'C.UTF-8'                       # locale for monetary formatting
./postgresql.conf:lc_numeric = 'C.UTF-8'                        # locale for number formatting
./postgresql.conf:lc_time = 'C.UTF-8'                           # locale for time formatting

The pg_upgradecluster command has an option --locale. We can run

pg_upgradecluster --locale=en_US.UTF-8 13 main

to set the locale en_US.UTF-8 for the upgraded database cluster.

pg_upgradecluster documentation:

       --locale=locale
           Set the default locale for the upgraded database cluster. If this option is not specified, the locale
           is inherited from the old cluster.

Reference: https://manpages.ubuntu.com/manpages/trusty/man8/pg_upgradecluster.8.html

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I'll try this out next time I have a window to do the upgrade, should be this week, and then I'll report back / mark as accepted answer.
Sadly this did not help, the error is still the same, notably the LC_CTYPE: UTF-8 part is still the problem.
The question is not on-topic for Stack Overflow as defined in the help center. Please don't answer such questions; instead, you should flag them for attention and they will be closed or migrated appropriately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.