<>initdb: invalid locale settings

experiment 1:

PostgreSQL Initialization is required after installation data, After compiling and installing with source code , adopt initdb During initialization :
initdb: invalid locale settings; check LANG and LC_* environment variables
Cannot be initialized .

experiment 2:

use rpm After package installation , adopt postgresql-11-setup initdb Time , Initialization was successful , But the default character set is SQL_ASCII:
postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype |
Access privileges
-----------+----------+-----------+-------------+-------------+----------------------
postgres| postgres | SQL_ASCII | C | C | template0 | postgres | SQL_ASCII | C |
C| =c/postgres + | | | | | postgres=CTc/postgres template0 | postgres |
SQL_ASCII| C | C | =c/postgres + | | | | | postgres=CTc/postgres
But check it out locale:
bash-4.2$ locale LANG=en_US.UTF-8 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=
The system character set is OK , It's what you want en_US.UTF-8.

resolvent :

Through these two experiments, it is found that it is related to the character set ,mysql You can modify the default character set through a configuration file , however postgresql It can't be , Once initialized server_encoding It can't be modified :
postgres=# show server_encoding; server_encoding ----------------- SQL_ASCII (
1 row) postgres=# alter system set server_encoding = 'UTF8'; ERROR: parameter
"server_encoding" cannot be changed postgres=#

and template0 The character set of is also not modifiable , If SQL_ASCII In the case of template0 For template , Through the create Add after statement template=template0
encoding='UTF8’ To create UTF8 New library of character set . If it's not as much trouble , It can also be modified template1 The character set of is UTF8, Because it is not specified template, Will default to template1 For template .

Although the character set has been modified , But the symptoms are not the root cause .

experiment 1 Can not be initialized , For the use of initdb Direct initialization data The situation , Can be added -E 'UTF8’ To display the specified default character set to complete initialization .

For experiments 2, The command used is postgresql-11-setup
initdb, The command is not supported -E parameter , Or can't default on initialization UTF8, and locale The character set found is also en_US.UTF-8, no problem , In fact, the reason is that locales There is no corresponding language pack in :
bash-4.2$ locale -a C POSIX
This often occurs in docker in , Because a lot of things have been castrated for the sake of mirror image , There is no such container at present en_US.UTF-8 Language pack , Installation method :
yum remove glibc-common -y yum install glibc-common -y localedef -v -c -i
en_US -f UTF-8 en_US.UTF-8
Re execution locale -a You can find out more en_US.utf8, At this time, the new initdb, start-up , find :
postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype |
Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres| postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres |
UTF8| en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres
template1| postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | |
postgres=CTc/postgres (3 rows)
If used dockerfile To create docker You can add environment variables to set the default character set :
ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing