How to Fix "perl: warning: Setting locale failed." Error in psql

2981
Share:
how-to-fix-perl-warning-setting-locale-failed-error-in-psql

If you're being greeted by this error:

perl: warning: Setting locale failed.

when running psql or any other Perl scripts, most common cause is due to the language/locale settings in use by the client machine that is connecting via SSH. If your client machine uses a different locale, your SSH connection likely forwards the environment settings over via SSH to the connecting server, and if the locale environments sent are not supported, you may encounter this message.

For example, this is the complete error in my terminal looks like:

$ psql --version
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_ADDRESS = "id_ID.UTF-8",
LC_NAME = "id_ID.UTF-8",
LC_MONETARY = "id_ID.UTF-8",
LC_PAPER = "id_ID.UTF-8",
LC_IDENTIFICATION = "id_ID.UTF-8",
LC_TELEPHONE = "id_ID.UTF-8",
LC_MEASUREMENT = "id_ID.UTF-8",
LC_NUMERIC = "id_ID.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").
psql (PostgreSQL) 14.1 (Debian 14.1-1.pgdg110+1)

In my case, it shows the error due to LANGUAGE and LC_ALL being unset. To remove above warning, we just need to set LC_ALL environment variable before connecting with ssh. Setting this environment variable is pretty easy. Prepend your remote host's available locale before the ssh command like below:

$ LC_ALL="en_US.utf-8" ssh user@host

Now we can see that our previous warning has gone.

Perl Warning Setting Locale Failed
Tags Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *